I try to setup a database connection in java with JNDI in combination with eclipseLink/JPA on Tomcat 5.5. I already configured the JNDI resource in web.xml and context.xml.
Just add the class JPAEclipseLinkSessionCustomizer to your project and configure the persistence.xml as shown below:
<persistence-unit name="yourUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/yourDs</non-jta-data-source>
<properties>
<property name="eclipselink.session.customizer" value="com.company.yourproject.yourpackage.JPAEclipseLinkSessionCustomizer"/>
</properties>
</persistence-unit>
You need this workaround only for Apache Tomcat.
Set the datasource URL to "jdbc/myDs"
<non-jta-data-source>jdbc/myDs</non-jta-data-source>
Year 2015 actualisation: I not sure Eclipselink SessionCustomizer is required. In my test all work without (Tomcat 7.x, Java 7.x, Eclipselink 2.4.x).
Some older materials suggest specific problem with Tomcat 5/6 and special way to resolve it.
I think you need to code a workaround for the javax.naming.NamingException: This context must be accessed throught a java: URL
exception as detailed at http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer
Also see this link which debugs through the problem
http://forums.java.net/jive/message.jspa?messageID=158622
I hope you could solve the problem with the comments given ...
I fix it by adding a property "javax.persistence.nonJtaDataSource" with the same value as the element non-jta-data-source