如何使用JPA设置Eclipselink? [英] How to setup Eclipselink with JPA?

查看:547
本文介绍了如何使用JPA设置Eclipselink?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Eclipselink文档说我需要在我的pom.xml中输入以下条目才能获得它与Maven:

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;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
  </repository>    
      ...
</repositories> 

但是当我尝试使用 @Entity 注释NetBeans告诉我,该类无法找到。事实上:Eclipselink的javax.persistence包中没有Entity类。

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.

如何使用Maven设置Eclipselink?

How do I have to setup Eclipselink with Maven?

推荐答案

eclipselink 工件不提供JPA 2.0 API ,您需要添加 javax.persistence

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;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>
  ...

为简单起见,我建议使用非OSGI EclipseLink jar。

I recommend to use the non OSGI EclipseLink jar for the sake of simplicity.

这篇关于如何使用JPA设置Eclipselink?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆