Apache TomEE ships with OpenJPA as the default JPA provider, however any valid JPA provider can be used.
The basic steps are:
Any webapp can specify the JPA provider it would like to use via the persistence.xml file, which can be at any of the following locations in a webapp
A single webapp may have many persistence.xml files and each may use whichever JPA provider it needs. The following is an example of a fairly common persistence.xml for DataNucleus
<persistence version="1.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_1_0.xsd"> <persistence-unit name="movie-unit"> <provider>org.datanucleus.api.jpa.PersistenceProviderImpl</provider> <jta-data-source>movieDatabase</jta-data-source> <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source> <properties> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> </properties> </persistence-unit> </persistence>
Note that you may have to set the persistence property datanucleus.jtaLocator and datanucleus.jtaJndiLocation to find your JNDI data sources.
The default JPA provider can be changed at the server level to favour DataNucleus over OpenJPA. Using the <tomee-home>/conf/system.properties file or any other valid means of setting java.lang.System.getProperties(), the following standard properties can set the default for any persistence.xml file.
javax.persistence.provider javax.persistence.transactionType javax.persistence.jtaDataSource javax.persistence.nonJtaDataSource
So, for example, DataNucleus can become the default provider via setting
CATALINA_OPTS=-Djavax.persistence.provider=org.datanucleus.api.jpa.PersistenceProviderImpl
You must of course add the DataNucleus libraries to <tomee-home>/lib/ for this to work.
Jars needed for DataNucleus 4.x:
Add: <tomee-home>/lib/datanucleus-core-4.0.0-m4.jar <tomee-home>/lib/datanucleus-api-jpa-4.0.0-m4.jar <tomee-home>/lib/datanucleus-rdbms-4.0.0-m4.jar Remove (optional): <tomee-home>/lib/asm-3.2.jar <tomee-home>/lib/commons-lang-2.6.jar <tomee-home>/lib/openjpa-2.2.0.jar <tomee-home>/lib/serp-1.13.1.jar