TomEE and DataNucleus JPA

Apache TomEE ships with OpenJPA/EclipseLink as the default JPA provider (depending on version of TomEE), however any valid JPA provider can be used.

The basic steps are:

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

Webapp Configuration

Any web-app 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 web-app 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/EclipseLink. 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):
<tomee-home>/lib/openjpa-2.2.0.jar (or EclipseLink)