5 Replies Latest reply on Apr 11, 2006 8:43 AM by tazly

    simple stateful session bean classcast exception

    eielk

      based on the trailblazer online examples, i setup a super simple stateless session bean (TestSLSB) and a stateful session bean(TestSFSB). note: using jboss 4.0.3sp1.

      they both show up in the jndi output, and the stateless works like a champ, but the stateful keeps throwing classcast exceptions on lookup?

      java.lang.ClassCastException: $Proxy70

      what is wrong, is the trailblazer example incorrect?

      import java.io.Serializable;
      
      import javax.ejb.Init;
      import javax.ejb.Local;
      import javax.ejb.Stateful;
      import org.jboss.annotation.ejb.LocalBinding;
      
      @Stateful
      @Local ({TestSFSBIF.class})
      @LocalBinding (jndiBinding="gwig/TestSFSBLocal")
      public class TestSFSB implements TestSFSBIF,Serializable
      {
       private int count = 0;
      
       public String getInfo()
       {
       count++;
       return "counter is ..."+count;
       }
      
       public int getCount(){return count;}
      
       @Init
       public void init()
       {
       count=70;
       }
      }
      


      i use this in my servlet client:
       TestSFSBIF testF = null;
       try {
       InitialContext ctx = new InitialContext();
       testF = (TestSFSBIF) ctx.lookup("gwig/TestSFSBLocal");
       }catch (Exception e) {
       ...
      


      here is my jndi snippet:
       +- gwig (class: org.jnp.interfaces.NamingContext)
       | +- TestSLSBLocal (proxy: $Proxy75 implements No ClassLoaders found for: com.gwig.ejb.TestSLSBIF (no security manager: RMI class loader disabled))
       | +- TestSFSBLocalStatefulProxyFactory (class: org.jboss.ejb3.stateful.StatefulLocalProxyFactory)
       | +- TestSFSBLocal (class: java.lang.Object)
      


      thanks.

        • 1. Re: simple stateful session bean classcast exception
          eielk

          sorry but here is some additional info:

          1. using ejb3
          2. i did notice that the trailblazer works with 4.0.4 only, but my question still stands, why can't i lookup the stateful session bean?

          • 2. Re: simple stateful session bean classcast exception
            eielk

            update: upgraded to 4.0.4RC1 and i get the same classcast exception! doh!

            anyone have any ideas? should i be getting a statefulproxyfactory first since that is what is loaded into jndi?

            • 3. Re: simple stateful session bean classcast exception
              eielk

              anyone?
              no one has run into this? come on... i don't believe it.

              i've been thru all of the tutorials and trailblazers, this is not complex but the client lookup just doesn't work for a stateful session bean...

              i found another posting on the wiki site that talks about classcastexception for multiple deployments of the same class, so i made sure my .war had only the interfaces and the ejb.jar had interfaces and impls. all wrapped up nicely in an ear...but it still gave the same error.

              help!

              • 4. Re: simple stateful session bean classcast exception
                starksm64

                The war should not have the interfaces when using the default war first class loading mode as this results in inconsistent types.

                • 5. Re: simple stateful session bean classcast exception
                  tazly

                   

                  "scott.stark@jboss.org" wrote:
                  The war should not have the interfaces when using the default war first class loading mode as this results in inconsistent types.


                  That finally solved the problem!

                  For the sake of usablity, this hint should be in the error message when getting a ClassCastException on EJB3 lookup, when classnames are identical and classloaders differ. Especially because in the old ways of J2EE, the EJB-interfaces have to be present in the war - now they are not allowed to.