Skip to main content

Provide EntityManagerFactory via JNDI lookup to webapp

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
chris.joelly
Offline
Joined: 2011-08-02

Hello,

i want to get the EntityManagerFactory for a persistence unit in a webapp using JNDI. What do i need to do to get the thing working?

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="web">
<jta-data-source>jdbc/Web</jta-data-source>
<properties>
...
</properties>
</persistence-unit>
</persistence>

web.xml ?

	<persistence-context-ref>
<persistence-context-ref-name>persistence/web</persistence-context-ref-name>
<persistence-unit-name>web</persistence-unit-name>
</persistence-context-ref>

JNDI name ?
using java:comp/env/persistence/web i get a NamingException stating that the name is not found, and when i use list-jndi-entries with asadmin i can not list the persistence context.

Thanks for any hint