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