Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1293
  • Last Modified:

How to deploy and access stateful session bean in JBOSS


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

  • 2
1 Solution
svgkrajuAuthor Commented:
Is there anybody who can answer my question?
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 ?
svgkrajuAuthor Commented:
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.

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now