5 Replies Latest reply on Nov 9, 2004 12:46 PM by Bill Burke

    ctx.lookup("java:comp/EntityManager") doesn't work on client

    Changshin Lee Newbie

      I made a program outside the server to get an EntityManager. Here's the lookup part:

      InitialContext ctx = new InitialContext();
      manager = (EntityManager) ctx.lookup("java:comp/EntityManager");

      It ended up with the following error:
      Exception in constructor: testExistence (javax.naming.NameNotFoundException: comp not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:495)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:503)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:509)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:253)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:529)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:508)
      at javax.naming.InitialContext.lookup(InitialContext.java:351)
      at ias.TestTaxiItem.(TestTaxiItem.java:17)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
      at junit.framework.TestSuite.createTest(TestSuite.java:131)
      at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
      at junit.framework.TestSuite.(TestSuite.java:75)
      at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.(JUnitTestRunner.java:225)
      at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.(JUnitTestRunner.java:177)
      at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:651)
      at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:558)

      I followed the spec, so EJB 3 PR1 (and maybe PR2) hasn't implemented it yet?



        • 1. Re: ctx.lookup(
          Bill Burke Master

          EntityManager is currently not available outside the container as the EJB 3 Expert group has not defined a way to access the EntityManager outside the container or the rules for it.

          The EJB3 expert group has also not defined how the EntityManager is available for access within a WAR or even if it is allowed to access the EntityManager outside the scope of the EJB3 jar.

          FYI, the java:comp space for EJB3 is the constant:


          We're in the process of refactoring how ENC is resolved in JBoss.


          • 2. Re: ctx.lookup(
            Changshin Lee Newbie

            Thanks for your answer. In my opinion, clients also should be able to have access to EntityManager through JNDI with the predefined name java:comp/EntityManager as described at section 8.1.3 in the spec.


            • 3. Re: ctx.lookup(
              Bill Burke Master

              java:comp is only available on the server or within a J2EE Client Container.

              I agree that EntityManager should be available outside the container. This is something the EJB3 specification should solve eventually.


              • 4. Re: ctx.lookup(
                Changshin Lee Newbie

                Are there any references for using a Client Container on JBoss? I couldn't find one. (Or, just configuration for JNDI means your application runs on a client container?)



                • 5. Re: ctx.lookup(
                  Bill Burke Master

                  We have a client container as required by the J2EE 1.4 certification...don't ask me how to use it though :)