TomEE and DataNucleus JPA

Apache TomEE ships with OpenJPA as the default JPA provider, however any valid JPA provider can be used.

The basic steps are:

  • Add the DataNucleus jars to <tomee-home>/lib/
  • Configure the webapp or the server to use DataNucleus.

Webapp Configuration

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

  • WEB-INF/persistence.xml of the .war file
  • META-INF/persistence.xml in any jar located in WEB-INF/lib/

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"

    <persistence-unit name="movie-unit">

            <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>

Note that you may have to set the persistence property datanucleus.jtaLocator and datanucleus.jtaJndiLocation to find your JNDI data sources.

Server Configuration

The default JPA provider can be changed at the server level to favour DataNucleus over OpenJPA. Using the <tomee-home>/conf/ 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.


So, for example, DataNucleus can become the default provider via setting


You must of course add the DataNucleus libraries to <tomee-home>/lib/ for this to work.

DataNucleus libraries

Jars needed for DataNucleus 4.x:


Remove (optional):