I use the javax.persistence
artifact (and not the eclipselink
artifact) from the EclipseLink Maven repository to access the JPA 2 API classes. Snippets from POM include:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
...
<repositories>
...
<repository>
<id>EclipseLink Repo</id>
<!-- note that ampersands in this URL are escaped because this is in an
xml file - un-escape them to use in browser -->
<url>http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo</url>
</repository>
...
</repositories>
...
</project>
The javax.persistence
artifact contains all the API classes, and none of the EclipseLink classes (except for two), allowing you to specify the scope as provided; this applies even for the EclipseLink JPA provider as well (which is in the eclipselink
artifact Id).
I haven't mixed the javax.persistence
artifact with the hibernate-entitymanager
artifact, which is how I managed the dependency for another project that relies on Hibernate EntityManager instead of EclipseLink for the JPA provider. A snippet from the second project's POM is shown below:
<project>
<dependencies>
...
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.5.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
...
</project>
I do change the dependency scopes from provided
to test
in other projects to ensure that unit tests will have a JPA provider in the classpath. This is primarily done to mask out the side-effects of using the javaee-api
dependency, which I use in the parent POM to allow compile time references to several Java EE 6 API classes.