2

我正在尝试在使用 maven、jpa、hibernate 和 hyperjaxb 的 eclipse 项目中升级到 JPA 2.1。当我尝试Run As..Run on Server从 Eclipse 中执行操作时出现以下错误:

java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

mvn dependency:tree在项目的根文件夹上运行,问题似乎是 hyperjaxb3 使用的是 JPA 2.0,与 JPA 2.1 冲突。有没有办法让 hyperjaxb3 使用 JPA 2.1?或者是否有其他方法可以解决此错误,以便我的应用程序无需删除 hyperjaxb3 即可获得 JPA 2.1 的好处?

这是我从mvn dependency:treewindows 命令行的 eclipse 项目的根文件夹中得到的输出:

[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MyApp 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ MyApp ---
[WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2
[INFO] org.springframework.samples:MyApp:war:1.0.0-SNAPSHOT
[INFO] +- org.jvnet.hyperjaxb3:hyperjaxb3-ejb-runtime:jar:0.6.0:compile
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO] |  \- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.8.2:compile
[INFO] +- org.jvnet.hyperjaxb3:hyperjaxb3-ejb-roundtrip:jar:0.6.0:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[INFO] |  +- org.jvnet.jaxb2_commons:jaxb2-basics-testing:jar:0.8.2:compile
[INFO] |  |  +- xmlunit:xmlunit:jar:1.0:compile
[INFO] |  |  \- org.jvnet.jaxb2_commons:jaxb2-basics-tools:jar:0.8.2:compile
[INFO] |  |     \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  \- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] |     \- log4j:log4j:jar:1.2.16:compile
[INFO] +- org.jadira.usertype:usertype.core:jar:3.1.0.CR8:compile
[INFO] |  \- org.jadira.usertype:usertype.spi:jar:3.1.0.CR8:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- javax.servlet.jsp:jsp-api:jar:2.2:provided
[INFO] +- org.springframework.data:spring-data-jpa:jar:1.6.4.RELEASE:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.8.4.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.0.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.0.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-core:jar:4.0.6.RELEASE:compile
[INFO] |  \- org.slf4j:jcl-over-slf4j:jar:1.7.7:runtime
[INFO] +- org.springframework:spring-jdbc:jar:4.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.0.6.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.0.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.0.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:4.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-tx:jar:4.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:4.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-oxm:jar:4.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-jms:jar:4.0.6.RELEASE:compile
[INFO] +- org.apache.tomcat:tomcat-jdbc:jar:7.0.42:runtime
[INFO] |  \- org.apache.tomcat:tomcat-juli:jar:7.0.42:runtime
[INFO] +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.0.13:runtime
[INFO] |  \- ch.qos.logback:logback-core:jar:1.0.13:runtime
[INFO] +- joda-time:joda-time:jar:2.3:compile
[INFO] +- joda-time:joda-time-hibernate:jar:1.3:compile
[INFO] +- joda-time:joda-time-jsptags:jar:1.1.1:compile
[INFO] +- org.jadira.usertype:usertype.jodatime:jar:2.0.1:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.27:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.2.1.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:4.2.1.Final:compile
[INFO] |  |  \- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction api_1.1_spec:jar:1.0.1.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] +- org.hibernate:hibernate-validator:jar:5.1.1.Final:compile
[INFO] |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] +- org.hibernate:hibernate-ehcache:jar:4.2.1.Final:compile
[INFO] +- net.sf.ehcache:ehcache-core:jar:2.6.6:compile
[INFO] +- org.webjars:bootstrap:jar:2.3.0:compile
[INFO] +- org.webjars:jquery-ui:jar:1.10.3:compile
[INFO] +- org.webjars:jquery:jar:2.0.3-1:compile
[INFO] +- org.springframework:spring-test:jar:4.0.6.RELEASE:test
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] +- org.aspectj:aspectjrt:jar:1.7.4:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.7.4:runtime
[INFO] +- com.github.dandelion:datatables-jsp:jar:0.9.2:compile
[INFO] |  \- com.github.dandelion:datatables-core:jar:0.9.2:compile
[INFO] |     +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] |     \- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] +- com.github.dandelion:datatables-export-itext:jar:0.9.2:compile
[INFO] |  \- com.itextpdf:itextpdf:jar:5.3.4:compile
[INFO] +- com.github.dandelion:datatables-servlet2:jar:0.9.2:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.2:compile
[INFO] +- commons-io:commons-io:jar:1.3.2:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.apache.tiles:tiles-jsp:jar:2.1.3:compile
[INFO] |  \- org.apache.tiles:tiles-servlet:jar:2.1.3:compile
[INFO] |     \- org.apache.tiles:tiles-core:jar:2.1.3:compile
[INFO] |        +- org.apache.tiles:tiles-api:jar:2.1.3:compile
[INFO] |        \- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] +- org.springframework.security:spring-security-core:jar:3.2.2.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.2.2.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.2.2.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-taglibs:jar:3.2.2.RELEASE:compile
[INFO] |  \- org.springframework.security:spring-security-acl:jar:3.2.2.RELEASE:compile
[INFO] +- org.eclipse.emf:ecore:jar:2.2.3:compile
[INFO] \- org.eclipse.emf:common:jar:2.2.3:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.805s
[INFO] Finished at: Thu Nov 06 12:32:32 PST 2014
[INFO] Final Memory: 14M/124M
[INFO] ------------------------------------------------------------------------
4

1 回答 1

1

org.hibernate.javax.persistence:hibernate-jpa-2.0-api由于范围内的org.jvnet.hyperjaxb3:hyperjaxb3-ejb-roundtrip依赖关系,您会遇到冲突compile。这实际上是不正确的,应该 provided改为。可以安全地假设提供hyperjaxb3-ejb-roundtrip了 JPA API 以及hyperjaxb3-ejb-runtime。这将在未来的版本中更正。

首先,确定你真的需要hyperjaxb3-ejb-roundtrip. 仅当您生成往返测试用例时才需要这样做 - 这实际上仅适用于“操场”。在生产项目中,您通常不需要这个。因此,您很可能会关闭往返测试用例生成并删除hyperjaxb3-ejb-roundtrip依赖项。

接下来,如果您确实需要hyperjaxb3-ejb-roundtrip,您可以使用 Maven 的依赖排除机制来排除hibernate-jpa-2.0-api依赖,因为hyperjaxb3-ejb-roundtrip. 这看起来像:

<dependency>
    <groupId>org.jvnet.hyperjaxb3</groupId>
    <artifactId>hyperjaxb3-ejb-roundtrip</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

如果您已经hyperjaxb3-ejb-runtime直接包含,您也可以将其排除在hyperjaxb3-ejb-roundtrip.

接下来,我刚刚在这个测试项目中试用了 JPA 2.1 兼容性。我必须更新hsqldb到,2.3.2但除此之外,它还可以与hibernate-entitymanagerversion4.3.7.Finalhibernate-jpa-2.1-apiversion一起使用1.0.0.Final。该测试没有特别的代表性,但它很好地表明 Hyperjaxb 与 JPA 2.1 兼容。JPA 2.1 很可能与 JPA 2.0 向后兼容,因此实际上 Hyperjaxb 生成的代码也应该与 JPA 2.1 兼容。

我现在提交了两个问题,一个只是将 Hyperjaxb 迁移到 JPA 2.1,另一个是支持新的 JPA 2.1 功能

迁移到 JPA 2.1 应该非常简单,因为它(希望)只需要更新依赖版本,并且在少数情况下(例如hibernate-jpa-2.x-api)还需要更新工件 id。HSQLDB 必须更新到org.hsqldb:hsqldb版本2.3.2和更高版本,但这没什么大不了的。我将在下一个版本中实现它。

支持新的 JPA 2.1 功能需要做更多的工作。


现在是一个小旁注。在发布跳转共享其他外部资源的链接时,请明确说明所链接资源的许可或法律状态。我将仅就可以安全地作为测试或样本添加到项目中的资源进行无偿咨询,以造福所有用户

于 2014-11-08T11:58:24.833 回答