title: Accessing Stateful session bean from servlet/jsp throws ClassCast exception in jboss 4.2.2
body: <p>Whenever I try to access EJB 3 Stateful session bean deployed on JBoss 4.2.2 application server using a web client(within JBoss server) such as servlet/jsp , I get following exception
  java.lang.ClassCastException: $Proxy123
  If I use application client , same code works without any exception.
  Or if I change bean to @Stateless , even web client works fine.
  If I deploy my .war on the tomcat container externally, again web client works fine for stateful bean also.</p>
  
  <p>So in short : Stateful bean EJB 3 deployed on JBoss 4.2 and accessed via web client deployed on JBoss throws classcastexception</p>
  
  <p>This is my code - client side, written in a servlet </p>
  
  <p>Properties properties = new Properties();
   properties.put(Context.INITIAL_CONTEXT_FACTORY,  "org.jnp.interfaces.NamingContextFactory");
              properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");</p>
  
  <pre><code>        Context c = new InitialContext(properties);
          InvokePOJORemote ref = (InvokePOJORemote) c.lookup("InvokePOJOBean/remote");
          out.println("&lt;h1&gt;Servlet ejb ref " + ref + "&lt;/h1&gt;");
          boolean sts = ref.addEmployee("Mad", (short) 30, new java.math.BigDecimal(12000));
  </code></pre>
  
  <p>This throws ClasscastException at the lookup statement , at time of casting. Dont know what is wrong! Pls help.</p>