JPA 2.1 (Java EE 7) – working persistence.xml file

I finally got a working persistence.xml for Java EE 7 up and running! With JPA 2.1 generation of the schema is now standardized. This means that you don’t have to use implementation specific flags, such as “eclipselink.ddl-generation” to auto-generate the schema. With Java EE 7, the location of the schema files/namespace has also changed. Below is a working file.

<persistence version="2.1" xmlns="" 
    <persistence-unit name="actionbazaar2" transaction-type="JTA">
            <property name="javax.persistence.schema-generation.database.action" value="create"/>
            <property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
            <property name="javax.persistence.schema-generation.scripts.drop-target" value="/tmp/mydrop.ddl"/>
            <property name="javax.persistence.schema-generation.scripts.create-target" value="/tmp/mycreate.ddl"/>
            <property name="eclipselink.deploy-on-startup" value="true"/>

This works on Glassfish 4 b84. At this point the files have to be included per defect GLASSFISH-19862. Note this is using a milestone release of EclipseLink M10 to be exact. To your pom.xml file you will need the following entries for Eclipselink and Java EE 7 respectively:

            <name>Repository for library EclipseLink (JPA 2.x)</name>

These dependencies are time sensitive. Consult these links for more information:

2 responses to “JPA 2.1 (Java EE 7) – working persistence.xml file

  1. Thank you. It helped a lot.

  2. Thanks for this tutorial. I need it for file persistenc.xml