I have a working persistence definition that works on java level tests. Now I want to incorporate that into a web application which defines the database connection as JNDI in the context.xml. What do I need to change to make it work with the JNDI instead of the persistence.xml or at least get the infor from there?
Your persistence.xml beginning should be something like this (using EclipseLink as implementation), for a jdbc/MYNAME JNDI name:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/MYNAME</non-jta-data-source>
<class>org.test.entity.MyEntity</class>
...
</persistence-unit>
<persistence>
Of course you should set the configuration suitable for your environment. In the example I use a non-JTA DataSource: according to one of your comments, it seems your DataSource is not JTA-compliant. For Hibernate, the persistence provider should be different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With