在哪里可以找到JPA2 Maven依赖项?
我正试图构建一个与实现无关的maven模块,它依赖于JPA2。不幸的是,唯一的Maven JPA依赖项是基于JPA1的,因此,我不能使用EntityManager.detach()方法,因为这只是一个JPA2选项 理想情况下,我希望能够在Pom中指定javax.persistence依赖项,并要求应用程序/容器提供JPA2实现。不幸的是,我找不到任何这样的依赖在哪里可以找到JPA2 Maven依赖项?,maven,dependencies,jpa-2.0,Maven,Dependencies,Jpa 2.0,我正试图构建一个与实现无关的maven模块,它依赖于JPA2。不幸的是,唯一的Maven JPA依赖项是基于JPA1的,因此,我不能使用EntityManager.detach()方法,因为这只是一个JPA2选项 理想情况下,我希望能够在Pom中指定javax.persistence依赖项,并要求应用程序/容器提供JPA2实现。不幸的是,我找不到任何这样的依赖 现在我唯一的选择是将hibernate-jpa-2.0-api 1.0.0.FINAL声明为提供的依赖项吗?我使用eclipselink
现在我唯一的选择是将hibernate-jpa-2.0-api 1.0.0.FINAL声明为提供的依赖项吗?我使用eclipselink Maven存储库中的
javax.persistence
工件(而不是eclipselink
工件)来访问JPA2 api类。来自POM的代码片段包括:
<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>
在其他项目中,我确实将依赖范围从
提供的
更改为测试
,以确保单元测试在类路径中有一个JPA提供程序。这样做主要是为了掩盖使用的副作用,我在父POM中使用它来允许编译时引用几个Java EE 6 API类。Hibernate JPA 2类(javax.persistence…)如下所示:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
org.hibernate.javax.persistence
hibernate-jpa-2.0-api
1.0.1.最终版本
这是EclipseLink最相关的JPA2官方API:
<repositories>
<repository>
<url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url>
<id>eclipselink</id>
<layout>default</layout>
<name>Repository for library EclipseLink (JPA 2.0)</name>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
http://download.eclipse.org/rt/eclipselink/maven.repo/
日食
违约
库EclipseLink存储库(JPA2.0)
org.eclipse.persistence
javax.persistence
2.0.3
假如
与Hibernates API不同,这是来自官方规范,在使用Criteria API时支持更好的泛型。我知道这是一篇很老的文章,如果你想从实现上变得不可知,那么你应该改用Java EE API依赖项 只需将以下内容添加到您的POM中:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${jee.version}</version>
<scope>provided</scope>
</dependency>
爪哇
JavaEEAPI
${jee.version}
假如
其中${jee.version}是您想要的JavaEE版本。我目前正在使用7.0。它具有所有EJB、JPA和JSF API依赖项。到今天为止,我认为最新的依赖项是:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
org.hibernate.javax.persistence
hibernate-jpa-2.1-api
1.0.0.1决赛
以下是在maven中使用JPA的方法:
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.10.Final</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
org.hibernate.javax.persistence
hibernate-jpa-2.1-api
1.0.0.1决赛
编译
javax.transaction
javax.transaction-api
1.2
编译
org.hibernate
休眠实体管理器
4.3.10.最终版本
运行时
org.hibernate.javax.persistence
hibernate-jpa-2.1-api
org.jboss.spec.javax.transaction
jboss-transaction-api_1.2_规范
xml API
xml API
org.jboss.logging
jboss日志
通过向项目的pom.xml文件中添加几个依赖项,我能够解决我的Maven JPA2依赖项。有关依赖项的xml代码,请参见下面的内容。我通过在上向下搜索目录找到了最新的groupId和artifactId版本。我只是沿着目录树走,直到找到了和工件的metadata.xml文件。
注意:对的依赖才是真正带来成功的因素
org.hibernate
冬眠核心
5.2.1.最终版本
运行时
org.eclipse.persistence
org.eclipse.persistence.core
2.6.4
编译
org.eclipse.persistence
org.eclipse.persistence.jpa
2.6.4
编译
对于JPA2.2API,“官方”工件可从maven central获得,请参阅。请参阅[第一个答案][1]。[1] :据我所知,我还可以使用geronimo-jpa_2.0_规范依赖项。但是使用geronimo还是HibernateJPA依赖关系会有区别吗?如果我按照提供的范围来确定它的范围,这似乎是无关紧要的。根据一般原则(这里没有经验),我会使用一个您不打算在大多数测试中使用的实现中的一个。严格从编译时的角度来看,这将使您更加确信自己是独立于实现的。为什么要添加带有提供范围的答案?很抱歉,这是一个迟来的问题,但是如果您使用此依赖关系,您将无法构建可工作的persistence.xml文件,因为像eclipse和intellij这样的IDE无法解析类。我在这里遗漏了一点吗?如果你谈论的是纯API以外的实现类,那么你就没有它们了。如果您纯粹是直接使用API,则可以使用这种方法。在开发时,当您将代码粘贴到API时,您将拥有所有API类。来自任何JPA提供者的任何其他特定实现,如Hibernate或EclipseLink,那么您也需要添加它们的依赖项。javaee api
看起来仍然不完整。我还需要添加javax.servlet:javax.servlet api:3.1.0
。@Jarekczek,视情况而定。您可能与API版本不匹配。例如,JavaEEAPI7包含ServletAPI3.1,而JavaEEAPI6将包含ServletAPI3.0。
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>javax.transaction-api</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.10.Final</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.1.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.6.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.6.4</version>
<scope>compile</scope>
</dependency>