4 Replies Latest reply on Feb 16, 2007 4:17 PM by chamillard

    Local JNDI name for EntityManager?

    guava

      Hi,

      Does any one know the local JNDI name for EntityManager under JBossAS 4.0.5GA? I have a class that is not an EJB and I need an instance of EntityManager and I will need to do a local JNDI lookup.

      Thanks

        • 1. Re: Local JNDI name for EntityManager?
          alrubinger

          If you'd like to have the EntityManager and Factory accessible via JNDI, just add these to your persistence.xml (will place in Global scope):

          <property name="jboss.entity.manager.jndi.name"
           value="java:/entityManager" />
          <property name="jboss.entity.manager.factory.jndi.name"
           value="java:/entityManagerFactory" />


          S,
          ALR

          • 2. Re: Local JNDI name for EntityManager?
            chamillard

            (I'm not the original poster, but I'm having the same problem)

            Although I'm using 4.0.4.GA, I tried this by adding the following to my persistence.xml

            <property name="jboss.entity.manager.jndi.name"
             value="java:/CoreEntitiesEntityManager" />
            


            I then tried to do a JNDI lookup using

            Context ctx = new InitialContext();
            EntityManager em = (EntityManager) ctx.lookup("java:CoreEntitiesEntityManager");
            


            but I got the "standard" (at least for me)

            javax.naming.NameNotFoundException: CoreEntitiesEntityManager not bound


            exception when I ran the code.

            Does the recommended approach only work in 4.0.5.GA (and not 4.0.4.GA)?
            Does it matter that I'm doing this in a Cactus test case?
            Isn't there a default JNDI name for an entity manager for a deployed persistence unit? If so, what would the full name be (assuming the app is deployed in "MyApp.ear", with persistence unit name "mypersistenceunit")?

            Thanks.

            • 3. Re: Local JNDI name for EntityManager?
              chamillard

              Sorry, I'll answer a couple of my own questions after a little more research:

              No default JNDI name for entity manager, so iI need to explicitly include it in persistence.xml.

              I still can't get the JNDI lookup to work, though. I also tried using Resource injection (suggested in another post), but I end up with a null entity manager.

              Thanks.

              • 4. Re: Local JNDI name for EntityManager?
                chamillard

                Folks,

                Sorry to take up bandwidth; I figured it out. My problem was that I put the property tag outside the <persistence-unit> tag in persistence.xml. Putting it inside solved the problem.

                Cheers.