How to deploy and access stateful session bean in JBOSS

Posted on 2009-04-20
Last Modified: 2013-12-02

I have a one stateful and one stateless session bean in my project. Apart from that I have a servlet (deployed as a war) which interacts with both these stateful and stateless session beans. I am able to successfully interact with stateless session from my servlet. But for a stateful session lookup is giving "ClassCastException" when my servlet interact with stateful session bean. Don't know why. Surprisingly when I wrote a standalone java client, it was able to communicate properly with both the session beans. Not sure why I am getting "ClassCastException" when I am trying to contact Stateful session bean only from my servlet.


1) Why JNDI view of the Stateful session bean does not implement its remote interface?
2) I get LoginSession object when I call the method getLoginSession from a standalone java client. Why this fails when I call the same method from a servlet?

Can somebody help me to resolve this problem?
Stateful session bean:


@Stateful(name = "uhomeSession")

@Remote( { LoginSession.class })

public class LoginSessionBean implements LoginSession {

    @PersistenceContext(unitName = "Model")




public interface LoginSession {



JNDI view in JBOSS:


and JNDI VIEW is

 +- uhome (class: org.jnp.interfaces.NamingContext)

  |   +- DefaultSessionBean (class: org.jnp.interfaces.NamingContext)

  |   |   +- remote (proxy: $Proxy96 implements interface com.vs.uhome.model.session.DefaultSession,interface org.jboss.ejb3.JBossProxy)

  |   +- uhomeSession (class: org.jnp.interfaces.NamingContext)

  |   |   +- remote (class: java.lang.Object)

  |   |   +- remoteStatefulProxyFactory (proxy: $Proxy65 implements interface org.jboss.ejb3.ProxyFactory)

Doing lookup for LoginSession:


public static LoginSession getLoginSession() throws UnknownException, WarningException {

  LoginSession ls;

  Context ctx;

  try {

    ctx = getInitialContext();

  } catch (NamingException ne) {

    throw new Exception (ne);


  try {

    ls = (LoginSession)ctx.lookup("uhome/LoginSessionBean/remote");

    return ls;

  } catch (NamingException ne) {

    throw new Exception (ne);



ClassCastException while doing lookup:


java.lang.ClassCastException: $Proxy96 cannot be cast to com.vs.uhome.model.session.LoginSession









<!DOCTYPE application PUBLIC "-//Sun Microsystems,

Inc.//DTD J2EE Application 1.2//EN"



    <display-name>Uhome Application</display-name>











Open in new window

Question by:svgkraju

    Author Comment

    Is there anybody who can answer my question?
    LVL 19

    Expert Comment

    Strange enough because classcast exception showing that it tries to give you a proxy for defaultsessionbean
    Could you also post a code for you defaultsessionbean ?

    Accepted Solution

    I figured out the problem. While doing the build for ViewController, somehow stateful session classes were part of the war. After removing those classes, lookup is working fine.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
          Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now