9 Replies Latest reply on Sep 12, 2007 9:02 AM by kpiis

    Cannot get my first EJB 3.0 to work!!!

    seahsherley

      Hi guys,

      I have created a interface....

      package examples.session.stateful;

      public interface Count
      {
      public int count();
      public void set(int val);
      public void remove();
      }

      Then I have created a Stateful Bean to implements the above interface

      @Stateful(name = "CountingBean")
      @Remote(Count.class)
      @Interceptors(CountCallbacks.class)
      public class CountBean implements Count
      {
      ...........
      }

      I have deploy eveything in the jboss and run my client

      Count obj = (Count)ctx.lookup("CountingBean");

      It give a ClassCastException....

      When i ran the JMX-Console.... and click on the JNDIVIEW and click on the INVOKE button under the method list..... on the page display... I see the following:

      .......
      +- CountingBean (class: org.jnp.interfaces.NamingContext)
      | +- remote (class: java.lang.Object)
      | +- remoteStatefulProxyFactory (proxy: $Proxy72 implements interface org.jboss.ejb3.ProxyFactory)
      ........

      My question is... how come the CountingBean is not of class Count?????

      Thanks a million!!!!

        • 1. Re: Cannot get my first EJB 3.0 to work!!!
          clebert.suconic

          do like this

          @Remote
          public interface Count
          {
          public int count();
          public void set(int val);
          public void remove();
          }


          @Stateful(name = "CountingBean")
          public class CountBean implements Count
          {
          ...........
          }




          Then add the interceptors back.


          You missed the annotation on the interface.

          • 2. Re: Cannot get my first EJB 3.0 to work!!!
            alrubinger

            Just a quick glance, but this stands out...

            Count obj = (Count)ctx.lookup("CountingBean");


            ...and your JNDI tree shows you:

            +- CountingBean (class: org.jnp.interfaces.NamingContext)
            | +- remote (class: java.lang.Object)
            | +- remoteStatefulProxyFactory (proxy: $Proxy72 implements interface org.jboss.ejb3.ProxyFactory)


            Your proxy should be stored under "CountingBean/remote". So try:

            Count obj = (Count)ctx.lookup("CountingBean/remote");


            Don't know if you've seen the EJB3 Trailblazer yet, but if not, it's really a great starting point with working examples for simple EJB3s:

            http://trailblazer.demo.jboss.com/EJB3Trail/serviceobjects/slsb/index.html

            S,
            ALR

            • 3. Re: Cannot get my first EJB 3.0 to work!!!
              seahsherley

              Thanks for your reply...

              I have tried adding @Remote to the interface class, it wont work...

              I tried to use ctx.lookup("CountingBean/remote") it returns a javax.naming.Reference object.... I am expecting a Count object.

              • 4. Re: Cannot get my first EJB 3.0 to work!!!
                alrubinger

                Couple things, and again - just looking quickly:

                CountBean is remote...have it implement Serializable...

                But also check the JARs you're including on your client classpath - are you including jbossall-client.jar?

                S,
                ALR

                • 5. Re: Cannot get my first EJB 3.0 to work!!!
                  georges.goebel

                  Hi,

                  I have exactly the same problem. I have one stateless and one statefull session bean. But in the jndi view is see (class: java.lang.Object) for the local and remote interface of the sfsb. For the slsb the proxy implements the correct interface.
                  I tried to add the @Local or @Remote to the interface or class, adding jndibinding and a lot of other things. But I cannot get it to work.
                  I cannot get a session bean from a client (fat client or servlet in the same ear). I always get a proxy classcast exception.
                  Is there a bug some where because I read the same problem on several places.

                  Thanks for any help

                  • 6. Re: Cannot get my first EJB 3.0 to work!!!
                    georges.goebel

                    Hi,

                    I solved my problem by packaging the web application without the ejb classes. The ejb3 (session beans and entity beans) classes where 2 times in the ear. In the jar and the war file. After packageing them only in the jar it workes for me

                    • 7. Re: Cannot get my first EJB 3.0 to work!!!
                      georges.goebel

                       

                      "georges.goebel" wrote:
                      Hi,

                      I solved my problem by packaging the web application without the ejb classes. The ejb3 (session beans and entity beans) classes where 2 times in the ear. In the jar and the war file. After packageing them only in the jar it works for me


                      • 8. Re: Cannot get my first EJB 3.0 to work!!!
                        kpiis

                        Hello all,
                        I have the same question:
                        After deploying my statefull bean I get the ClassCastException
                        In JNDI view it's binded in such way
                        +- StatefullBean (class: org.jnp.interfaces.NamingContext)
                        | +- localStatefulProxyFactory (class: org.jboss.ejb3.stateful.StatefulLocalProxyFactory)
                        | +- local (class: java.lang.Object)

                        I am looking for the bean from servlet, StatefullBean class is not stored in servlet' WAR.

                        StatefullBean b = (StatefullBean)con.lookup("StatefullBean/local");
                        java.lang.ClassCastException: $Proxy250

                        With stateless beans I am working in the same way but without errors.

                        What I'm doing wrong?


                        • 9. Re: Cannot get my first EJB 3.0 to work!!!
                          kpiis

                          O, my bad -
                          IStatefullBean b = (IStatefullBean)con.lookup("StatefullBean/local")
                          it's correct.