5 Replies Latest reply on Aug 31, 2001 6:20 PM by Jesper Knudsen

    Problem looking up entity from session bean

    Jesper Knudsen Newbie

      I have created an entity bean for a zipcode table (DatZipCode) and a session bean (ZipCode) which calls it (e.g. tries to call it)

      Each bean are deployed in seperate .jar files. This works fine.

      The problem occures when the session bean try looking up the session bean.

      I lookup the session bean from my client application with:
      Context ctx = new javax.naming.InitialContext();
      Object ref = ctx.lookup("ejb/entity/DatZipCode");
      return (DatZipCodeHome) javax.rmi.PortableRemoteObject.narrow(ref, DatZipCodeHome.class);

      This works fine!

      But entity bean lookup inside the session bean:

      Context ctx = new javax.naming.InitialContext();
      System.out.println("got InitialContext()!");
      Object ref = ctx.lookup("ejb/entity/DatZipCode");
      System.out.println("done lookup");
      return (DatZipCodeHome) javax.rmi.PortableRemoteObject.narrow(ref, DatZipCodeHome.class);

      Fails!

      I have checked all deployment descriptors at they matches the lookup names.

      The funniest part of it is that when I lookup the entity bean directly from the client application it works fine.

      To me it looks like a problem inside the ejb container.
      But I might be wrong.

      Please help.

      Gr. Jesper

        • 1. Re: Problem looking up entity from session bean
          Hai Pham Newbie

          Hi,

          First, make sure that you have specify the reference to entity beans used in your session bean (this is the ejb-ref tag).

          Secondly, since your beans are deployed in separate jar files, you will need to provide more info in the jboss.xml file. This is specified somewhere in the jboss doc., I just can't find it now. Basically in that case, you have to specify the jndi class name and other info.

          • 2. Re: Problem looking up entity from session bean
            Jesper Knudsen Newbie

            I found something in the documentation (6. Advanced container configuration : use of jboss.xml), but it does not seem to work.

            My .xml files for the session bean now looks like this

            ejb-jar.xml:

            <?xml version="1.0" encoding="Cp1252"?>

            <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>

            <ejb-jar>
            <enterprise-beans>

            <ejb-name>ZipCode</ejb-name>
            com.orwtech.ebizz.ejb.session.ZipCodeHome
            com.orwtech.ebizz.ejb.session.ZipCodeRemote
            <ejb-class>com.orwtech.ebizz.ejb.session.ZipCode</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
            <ejb-ref>
            <ejb-ref-name>ejb/DatZipCode</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            com.orwtech.ebizz.ejb.entity.DatZipCodeHome
            com.orwtech.ebizz.ejb.entity.DatZipCode
            </ejb-ref>

            </enterprise-beans>
            <assembly-descriptor>
            <container-transaction>

            <ejb-name>ZipCode</ejb-name>
            <method-name>*</method-name>

            <trans-attribute>Required</trans-attribute>
            </container-transaction>
            </assembly-descriptor>
            </ejb-jar>

            jboss.xml:

            <?xml version="1.0" encoding="UTF-8"?>

            <enterprise-beans>

            <ejb-name>ZipCode</ejb-name>
            <jndi-name>ejb/session/ZipCode</jndi-name>
            <ejb-ref>
            <ejb-ref-name>ejb/DatZipCode</ejb-ref-name>
            <jndi-name>ejb/entity/DatZipCode</jndi-name>
            </ejb-ref>

            </enterprise-beans>


            I even tried putting the two .jar files into an .ear file with an application.xml. But I just can't get it to work.

            I get this stack trace from the session bean lookup:

            "javax.naming.NamingException: ejb not bound"

            Any suggestions?

            Gr. Jesper

            • 3. Re: Problem looking up entity from session bean
              Jesper Knudsen Newbie

              I have tried printing stack trace inside the session bean but I cannot decifer it. Someone else might?

              Gr. Jesper

              [Default] javax.naming.CommunicationException. Root exception is
              [Default] java.lang.ClassNotFoundException: com.orwtech.ebizz.ejb.entity.DatZipC
              odeHome
              [Default] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
              [Default]
              [Default] at java.security.AccessController.doPrivileged(Native Method)
              [Default]
              [Default] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
              [Default]
              [Default] at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
              [Default]
              [Default] at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
              [Default]
              [Default] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

              [Default]
              [Default] at java.lang.Class.forName0(Native Method)
              [Default]
              [Default] at java.lang.Class.forName(Class.java:195)
              [Default]
              [Default] at sun.rmi.server.MarshalInputStream.resolveProxyClass(MarshalIn
              putStream.java:183)
              [Default]
              [Default] at java.io.ObjectInputStream.inputProxyClassDescriptor(ObjectInp
              utStream.java:982)
              [Default]
              [Default] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:3
              70)
              [Default]
              [Default] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2
              36)
              [Default]
              [Default] at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:
              1186)
              [Default]
              [Default] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:3
              86)
              [Default]
              [Default] at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2
              36)
              [Default]
              [Default] at java.rmi.MarshalledObject.get(MarshalledObject.java:138)
              [Default]
              [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:35
              3)
              [Default]
              [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:33
              3)
              [Default]
              [Default] at javax.naming.InitialContext.lookup(InitialContext.java:350)
              [Default]
              [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:42
              1)
              [Default]
              [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:45
              7)
              [Default]
              [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:33
              3)
              [Default]
              [Default] at javax.naming.InitialContext.lookup(InitialContext.java:350)
              [Default]
              [Default] at com.orwtech.ebizz.ejb.session.ZipCode.getDatZipCodeHome(ZipCo
              de.java:89)
              [Default]
              [Default] at com.orwtech.ebizz.ejb.session.ZipCode.getAllZipCodes(ZipCode.
              java:44)
              [Default]
              [Default] at java.lang.reflect.Method.invoke(Native Method)
              [Default]
              [Default] at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.
              invoke(StatelessSessionContainer.java:543)
              [Default]
              [Default] at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.inv
              oke(StatelessSessionInstanceInterceptor.java:87)
              [Default]
              [Default] at org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxIntercept
              orCMT.java:133)
              [Default]
              [Default] at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(Tx
              InterceptorCMT.java:307)
              [Default]
              [Default] at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCM
              T.java:99)
              [Default]
              [Default] at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInte
              rceptor.java:128)
              [Default]
              [Default] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.ja
              va:195)
              [Default]
              [Default] at org.jboss.ejb.StatelessSessionContainer.invoke(StatelessSessi
              onContainer.java:286)
              [Default]
              [Default] at org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke
              (JRMPContainerInvoker.java:393)
              [Default]
              [Default] at java.lang.reflect.Method.invoke(Native Method)
              [Default]
              [Default] at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.jav
              a:241)
              [Default]
              [Default] at sun.rmi.transport.Transport$1.run(Transport.java:142)
              [Default]
              [Default] at java.security.AccessController.doPrivileged(Native Method)
              [Default]
              [Default] at sun.rmi.transport.Transport.serviceCall(Transport.java:139)
              [Default]
              [Default] at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTranspor
              t.java:443)
              [Default]
              [Default] at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPT
              ransport.java:643)
              [Default]
              [Default] at java.lang.Thread.run(Thread.java:484)
              [Default]

              • 4. Re: Problem looking up entity from session bean
                Horia Muntean Newbie

                Try to do something like this:

                Context ctx = new javax.naming.InitialContext();
                System.out.println("got InitialContext()!");
                Object ref = ctx.lookup("java:comp/env/ejb/DatZipCode");
                System.out.println("done lookup");
                return (DatZipCodeHome) javax.rmi.PortableRemoteObject.narrow(ref, DatZipCodeHome.class);

                And be sure to declare an ejb ref in the session bean section of the ejb-jar.xml
                <ejb-ref>
                <ejb-ref-name>ejb/DatZipCode</ejb-ref-name>
                <ejb-ref-type>Entity</ejb-ref-type>
                your.package.DatZipCodeHome
                your.package.DatZipCode
                <ejb-link>The name of the entity bean</ejb-link>
                </ejb-ref>

                I think the lookup made from the session bean doesn't work 'cause the jndi context is different from the jndi context obtained in the standalone client. So if u want to solve your problem u have to include an <ejb-ref> section in your session bean decriptor 'cause I guess at deployment the jboss will do an automatic bind of the entity bean ref in the jndi context of the session bean.

                • 5. Re: Problem looking up entity from session bean
                  Jesper Knudsen Newbie

                  Hi seven

                  Thank you for your good answer. I now got it to work thanks to your guidance.

                  Just to make this usefull to others I will add this comment to your reply.

                  Comment: To make it all work the entity bean and session bean has to be deployed in the same .ear file including application.xml

                  Sample of session bean ejb-jar.xml

                  <ejb-jar>
                  <enterprise-beans>

                  <ejb-name>ZipCode</ejb-name>
                  com.orwtech.ebizz.ejb.session.ZipCodeHome
                  com.orwtech.ebizz.ejb.session.ZipCodeRemote
                  <ejb-class>com.orwtech.ebizz.ejb.session.ZipCode</ejb-class>
                  <session-type>Stateless</session-type>
                  <transaction-type>Container</transaction-type>
                  <ejb-ref>
                  <ejb-ref-name>ejb/DatZipCode</ejb-ref-name>
                  <ejb-ref-type>Entity</ejb-ref-type>
                  com.orwtech.ebizz.ejb.entity.DatZipCodeHome
                  com.orwtech.ebizz.ejb.entity.DatZipCodeRemote
                  <ejb-link>ebizz/ejb/entity/DatZipCode</ejb-link>
                  </ejb-ref>

                  </enterprise-beans>
                  ...
                  </ejb-jar>

                  Sample of session bean jboss.xml


                  <enterprise-beans>

                  <ejb-name>ZipCode</ejb-name>
                  <jndi-name>ebizz/ejb/session/ZipCode</jndi-name>
                  <ejb-ref>
                  <ejb-ref-name>ejb/DatZipCode</ejb-ref-name>
                  <jndi-name>ebizz/ejb/entity/DatZipCode</jndi-name>
                  </ejb-ref>

                  </enterprise-beans>


                  Sample of .ear application.xml


                  <display-name>ZipCode test</display-name>

                  DatZipCode.jar


                  ZipCode.jar



                  Thank you all for your help!

                  Jesper