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

    Local JNDI name for EntityManager?

    guava Newbie


      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.


        • 1. Re: Local JNDI name for EntityManager?
          Andrew Rubinger Master

          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" />


          • 2. Re: Local JNDI name for EntityManager?
            Tim Chamillard Newbie

            (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")?


            • 3. Re: Local JNDI name for EntityManager?
              Tim Chamillard Newbie

              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.


              • 4. Re: Local JNDI name for EntityManager?
                Tim Chamillard Newbie


                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.