I\'m trying to build an implementation agnostic maven module which relies on JPA2. Unfortunately, the only Maven JPA dependency is JPA1 based, and consequently, I cannot us
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:
...
...
org.eclipse.persistence
javax.persistence
2.0.0
provided
...
...
EclipseLink Repo
http://www.eclipse.org/downloads/download.php?r=1&nf=1&file=/rt/eclipselink/maven.repo
...
...
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:
...
org.hibernate
hibernate-entitymanager
3.6.5.Final
provided
org.hibernate
hibernate-validator
4.2.0.Final
provided
...
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.