How to configure Eclipselink with JPA?

The Eclipselink documentation says that I need the following entries in my pom.xml to get it from Maven:

<dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.0.0</version> <scope>compile</scope> ... </dependency> <dependencies> ... <repositories> <repository> <id>EclipseLink Repo</id> <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url> </repository> ... </repositories> 

But when I try to use the @Entity annotation, NetBeans tells me that the class cannot be found. And indeed: there is no Entity class in the javax.persistence package from Eclipselink.

How do I configure Eclipselink with Maven?

+6
java java-ee maven-2 jpa eclipselink
source share
4 answers

eclipselink artifact eclipselink not provide JPA 2.0 API you need to add javax.persistence :

 <repositories> <repository> <id>eclipselink</id> <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo/</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.0.0</version> <scope>provided</scope><!-- since I'm running inside a Java EE container --> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>javax.persistence</artifactId> <version>2.0.0</version> <scope>provided</scope><!-- since I'm running inside a Java EE container --> </dependency> ... 

I recommend using the non OSGI EclipseLink jar for simplicity.

+13
source share

Just add the following to pom.xml .

Now these artifacts are in the maven repositories, so there is no need to add any <repository>

  <!-- JPA --> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>eclipselink</artifactId> <version>2.5.1</version> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>javax.persistence</artifactId> <version>2.0.0</version> </dependency> 



Or, if you are using the Java EE application server, use org.eclipse.persistence.jpa:org.eclipse.persistence , since it does not contain dependencies that are already on the server.

  <!-- JPA for Java EE application servers --> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa</artifactId> <version>2.5.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>javax.persistence</artifactId> <version>2.0.0</version> <scope>provided</scope> </dependency> 
+4
source share

When I look into my local maven repository, org.eclipse.persistence: eclipselink really contains a persistence api, at least for version 2.0.0-SNAPSHOT eclipselink.

But there is another set of dependencies in the eclipselink repository that are slightly more modular. These are the dependencies that I am using in the current project:

 <!-- persistence api --> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>javax.persistence</artifactId> <version>2.0.0</version> <scope>provided</scope> </dependency> <!-- jpa implementation --> <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>org.eclipse.persistence.jpa</artifactId> <version>2.0.2</version> <scope>provided</scope> </dependency> 

Note that the area is set as being provided, as I deploy to a glass fish that already contains eclipselink.

+2
source share

You can try add

 <dependency> <groupId>org.eclipse.persistence</groupId> <artifactId>javax.persistence</artifactId> <version>2.0.0</version> <scope>compile</scope> </dependency> 
0
source share

All Articles