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="http://xmlns.jcp.org/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence 
http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="actionbazaar2" transaction-type="JTA">
        <jta-data-source>jdbc/actionbazaar2</jta-data-source>
        <properties>
            <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"/>
        </properties>
    </persistence-unit>
</persistence>

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:

<repositories>
        <repository>
            <id>java.net-promoted</id>
            <url>https://maven.java.net/content/groups/promoted/</url>
        </repository>
        <repository>
            <url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url>
            <id>eclipselink</id>
            <layout>default</layout>
            <name>Repository for library EclipseLink (JPA 2.x)</name>
        </repository>
    </repositories>
    <dependencies>
        <dependency> 
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>2.5.0-M10</version>
            <scope>provided</scope>
        </dependency>
        <dependency>  
            <groupId>javax</groupId>  
            <artifactId>javaee-api</artifactId>  
            <version>7.0-b77</version>  
            <scope>provided</scope>
        </dependency>
    </dependencies>

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

Published by rcuprak

Ryan Cuprak is an e-formulation analyst at Enginuity PLM and president of the Connecticut Java Users Group that he has run since 2003. At Enginuity PLM he is focused on developing data integrations to convert clients’ data and also user interface development. Prior to joining Enginuity he worked for a startup distributed-computing company, TurboWorx, and Eastman Kodak’s Molecular Imaging Systems group, now part of Carestream Health. At TurboWorx he was a Java developer and also a technical sales engineer supporting both presales and professional services. Cuprak has earned a BS in computer science and biology from Loyola University Chicago. He is a Sun Certified NetBeans IDE Specialist. He can be contacted at rcuprak@acm.org.

2 thoughts on “JPA 2.1 (Java EE 7) – working persistence.xml file

Comments are closed.