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.
So in short : Stateful bean EJB 3 deployed on JBoss 4.2 and accessed via web client deployed on JBoss throws classcastexception
This is my code - client side, written in a servlet
Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
Context c = new InitialContext(properties);
InvokePOJORemote ref = (InvokePOJORemote) c.lookup("InvokePOJOBean/remote");
out.println("<h1>Servlet ejb ref " + ref + "</h1>");
boolean sts = ref.addEmployee("Mad", (short) 30, new java.math.BigDecimal(12000));
This throws ClasscastException at the lookup statement , at time of casting. Dont know what is wrong! Pls help.