3 Replies Latest reply on Sep 29, 2005 7:59 PM by kourosh bagheri

    EJB 3.0 with Servlets produces ClassCastException!

    kourosh bagheri Newbie

      Hi!

      I am developing a web shop with JBoss 4.0.3RC1, EJB 3.0, JSP and Servlets, with WIN XP and J2SE 1.5. My Database is mySQL 4.1.

      I have a SFSB Cart Bean, with a @Remote business interface.
      Trying to get the SFSB in the servlet (like the jboss ejb 3.0 trailblazers do)
      to work with it, I get the

      "java.lang.ClassCastException: $Proxy147"

      error, but just every 3-4 times, if I put a new ear file in the deploy dir (hot deploy), NOT ALWAYS!!!!!!

      My SFSB looks like this:

      @Stateful
      public class CartBean implements Carts{
      ...

      }

      The Business Interface :

      @Remote
      public interface Carts {
      ...
      }

      And finally the snippet in the servlet, which is shown as the source of the error:

      cartBean = (Carts) context.lookup(Carts.class.getName());
      ...

      Wenn I restart JBoss and do not change the source code, it works fine, but if I change something and insert the changed code (as ear file), I get this error:

      com.myfirm.myshop.web.MainServlet.init(MainServlet.java:84)
      javax.servlet.GenericServlet.init(GenericServlet.java:211)
      org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
       org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
       org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
       org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
       org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       java.lang.Thread.run(Thread.java:595)



      And after a new restart of JBoss the exceptions run off!!

      Does someone know the reason?

      Could it be a bug of jboss?

      thanx!




        • 1. Re: EJB 3.0 with Servlets produces ClassCastException!
          Bill Burke Master

          Do you have copies of your stateful interfaces in your war and ejb.jar? This would cause the CCE's.

          • 2. Re: EJB 3.0 with Servlets produces ClassCastException!
            kourosh bagheri Newbie

            Hi Bill,
            thanks for your reply..

            I use the JBoss IDE to do the things exactly the way, how the jboss tutorials (jboss ide-, jboss ejb 3.0 - and dvd store trails) demonstrate.

            I let JBoss IDE create 3 jar files, one .par, where the entities reside, one .ejb3 where the sfsb, slsb and invoker classes reside, and one .war file where the jsp, css, html and whithin the WEB-INF/classes directory the servlet reside.
            It is exactly the way the tutorials demonstrate, and it works fine but afte 2-3 changes, new packaging and hot deploying, jboss dose not let me run the application again. I get the CCE again and again. After a restart of jboss, I can work again, and everything is fine!

            What are you meaning with the ejb.jar? is it the jar file, where the sfsb and slsb and mdb reside?

            I took a look in that war file but there are no copies of my stateful interfaces. Those interfaces are just in the business.ejb3 file, where they reside beside the implementation clases (the bean classes itselves).
            But it looks exactly like the tutorials do.

            If you wish, I can send the business.ejb3 file to see it yourself.

            Thanks again.




            • 3. Re: EJB 3.0 with Servlets produces ClassCastException!
              kourosh bagheri Newbie

              It's really amazing!
              The same code, that throws the exceptions in the servlets, works fine in the jsp files!!
              But why?!