I was able to find the name by looking at the JNDI Tree view:
- Go to
http://localhost:8080/jmx-console
- Search for JNDIView and click the link
service=JNDIView
- Invoke button for the
list()
method.
- Search for the persistence name on the result tree view.
It looks like this:
Global JNDI Namespace
+- persistence.unit:unitName=tpar.ear (class: org.jnp.interfaces.NamingContext)
| +- tpar-jboss-ejb3.jar#JPADB (class: org.hibernate.impl.SessionFactoryImpl)
Though, the object is actually a SessionFactoryImpl and not an EntityManager.
Additionally, the jndi lookup string generated by JBoss is hideous:
jndi.lookup("persistence.unit:unitName=tpar.ear/tpar-jboss-ejb3.jar#JPADB");
By adding the following property to the persistence.xml
, I can look up using a shorter name while getting the object as an EntityManager at the same time:
<property name="jboss.entity.manager.jndi.name" value="tpar/entity-manager"/>
Note that using the long JNDI name still returns SessionFactoryImpl object in case anyone wants a SessionFactory.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…