views:

293

answers:

3

The Eclipselink documentation says that I need the following entries in my pom.xml to get it with 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;amp;nf=1&amp;amp;file=/rt/eclipselink/maven.repo&lt;/url&gt;
  </repository>    
      ...
</repositories> 

But when I try to use @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 have to setup Eclipselink with Maven?

A: 

You can try to add

<dependency>
   <groupId>org.eclipse.persistence</groupId>
   <artifactId>javax.persistence</artifactId>
   <version>2.0.0</version>
   <scope>compile</scope>
</dependency>
Mykola Golubyev
A: 

When I look into my local maven repository, org.eclipse.persistence:eclipselink does indeed contain the persistence api, at least for version 2.0.0-SNAPSHOT of eclipselink.

But there is another set of dependencies in the eclipselink repository that are a bit more modularized. These are the dependencies I am using in a 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 scope is set to provided since I deploy to glassfish which already contains eclipselink.

Jörn Horstmann
+1  A: 

The eclipselink artifact doesn't provide the 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;amp;nf=1&amp;amp;file=/rt/eclipselink/maven.repo/&lt;/url&gt;
  </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 to use the non OSGI EclipseLink jar for the sake of simplicity.

Pascal Thivent
I had already tried to add the dependency javax.persistence, but there is an error in NetBeans telling me that there is no `Entity` class. If I convert the same class to Java everything is fine. Your post led me to right place.
deamon