将hyperjaxb3升级到jpa 2.1 [英] upgrade hyperjaxb3 to jpa 2.1

查看:107
本文介绍了将hyperjaxb3升级到jpa 2.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我跑了 mvn dependency:tree 在项目的根文件夹中,问题似乎是hyperjaxb3正在使用JPA 2.0,这与JPA 2.1冲突。有没有办法让hyperjaxb3使用JPA 2.1?或者是否有其他解决此错误的方法,以便我的应用程序可以从JPA 2.1获益,而无需移除hyperjaxb3?



这里是输出我从Windows命令行的eclipse项目的根文件夹中获得了 mvn dependency:tree

  [信息] 
[信息] -------------------------------- ----------------------------------------
[INFO]构建MyApp 1.0 .0-SNAPSHOT
[INFO] --------------------------------------- ---------------------------------
[警告]神器org.apache.commons:commons- io:jar:1.3.2已经重新定位到commons-io:commons-io:jar:1.3.2
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli)@ MyApp ---
[警告]神器org.apache.commons:commons-io:jar:1.3.2已被重新定位到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:编译
[INFO] | + - org.apache.commons:commons-lang3:jar:3.2.1:compile
[INFO] | \- org.jvnet.jaxb2_commons:jaxb2-basics-runtime:jar:0.8.2:编译
[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:编译
[INFO] | | \- org.jvnet.jaxb2_commons:jaxb2-basics-tools:jar:0.8.2:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.1.1:编译
[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:提供
[信息] + - javax.servlet.jsp:jsp-api:jar:2.2:提供
[信息] + - org.springframework .data:spring-data-jpa:jar:1.6.4.RELEASE:编译
[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:编译
[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
[信息] + - org.springframework:spring-jms:jar:4.0.6.RELEASE :编译
[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:编译
[INFO] + - joda-time:joda-time-hibernate:jar:1.3:编译
[信息] + - joda-time:joda-time-jsptags:jar:1.1.1:编译
[信息] + - 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:编译
[INFO] | + - dom4j:dom4j:jar:1.6.1:编译
[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:编译
[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:编译
[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
[信息] + - org.aspectj :aspectjrt:jar:1.7.4:编译
[INFO] + - org.aspectj:aspectjweaver:jar:1.7.4:runtime
[INFO] + - com.github.dandelion:datatables-jsp :jar:0.9.2:编译
[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:编译
[INFO] + - com.github.dandelion:datatables -export-itext:jar:0.9.2:编译
[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:编译
[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:编译
[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:编译
[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] -------------------- -------------------------------------------------- -
[信息]建立成功
[信息] -------------------------------- ----------------------------------------
[信息]总时间: 9.805s
[INFO]完成时间:Thu Nov 06 12:32:32 PST 2014
[INFO] Final Memory:14M / 124M
[INFO] -------- -------------------------------------------------- --------------


解决方案

由于 org.jvnet.hyperjaxb3的原因,你得到了冲突的 org.hibernate.javax.persistence:hibernate-jpa-2.0-api hyperjaxb3-ejb-roundtrip 依赖项,它包含在 compile 范围内。这实际上是不正确的,应该是 提供 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 ,所以依赖性不会被过度排除。这看起来像这样:

 <依赖关系> 
< groupId> org.jvnet.hyperjaxb3< / groupId>
< artifactId> hyperjaxb3-ejb-roundtrip< / artifactId>
<排除项>
<排除>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.0-api< / artifactId>
< /排除>
< /排除>
< /依赖关系>

如果您已经包含 hyperjaxb3-ejb-runtime 你也可以将它从> hyperjaxb3-ejb-roundtrip 中排除。

接下来,我刚刚尝试过在此测试项目中支持JPA 2.1兼容性。我不得不将 hsqldb 更新为 2.3.2 ,但除​​此之外,它与 hibernate一起工作-entitymanager 版本 4.3.7.Final hibernate-jpa-2.1-api 版本 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功能需要更多工作。





现在有一个小方面的说明。在张贴链接到其他外部资源的链接时,请明确说明链接资源的许可证或合法身份。我会参考公益项目,只在可以安全地添加到项目中的所有用户的利益来源。



I am trying to upgrade to JPA 2.1 in an eclipse project that uses maven, jpa, hibernate, and hyperjaxb. I am getting the following error when I try to do Run As..Run on Server from within eclipse:

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

I ran mvn dependency:tree on the root folder of the project and the problem seems to be that hyperjaxb3 is using JPA 2.0, which conflicts with JPA 2.1. Is there some way to get hyperjaxb3 to use JPA 2.1? Or is there some other way to resolve this error so that my app can have the benefits of JPA 2.1 without having to remove hyperjaxb3?

Here is the output I got from mvn dependency:tree on the root folder of the eclipse project from the windows command line:

[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] ------------------------------------------------------------------------

解决方案

You get the conflicting org.hibernate.javax.persistence:hibernate-jpa-2.0-api because of the org.jvnet.hyperjaxb3:hyperjaxb3-ejb-roundtrip dependency which has it in compile scope. This is actually incorrect, should be provided instead. The hyperjaxb3-ejb-roundtrip may safely assume that JPA API as well as hyperjaxb3-ejb-runtime are provided. This will be corrected in the future release.

First of all, make sure you really need hyperjaxb3-ejb-roundtrip. This is only needed if you generate the roundtrip test case - which is actually only meant for "playground". In production projects you should normally not need this. So you may very well turn off the roundtrip test case generation and remove the hyperjaxb3-ejb-roundtrip dependency.

Next, if you do need hyperjaxb3-ejb-roundtrip you can use Maven's mechanism of dependency exclusion to exclude the hibernate-jpa-2.0-api dependency from being transitively excluded because of the hyperjaxb3-ejb-roundtrip. This will look something like:

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

If you already include hyperjaxb3-ejb-runtime directly, you may also exclude it from hyperjaxb3-ejb-roundtrip.

Next, I've just tried out JPA 2.1 compatibility in this test project. I had to update hsqldb to 2.3.2 but apart from that, it worked with hibernate-entitymanager version 4.3.7.Final and hibernate-jpa-2.1-api version 1.0.0.Final. The test is not especially representative, but it is a good indication that Hyperjaxb is compatible with JPA 2.1. JPA 2.1 is most probably backwards-compatible with JPA 2.0 so actually the code generated by Hyperjaxb should be compatible to JPA 2.1 as well.

I have now filed two issues, one to just move Hyperjaxb to JPA 2.1, the other one to support new JPA 2.1 features.

Moving to JPA 2.1 should be quite simple as it will (hopefully) only require to update the dependency versions and in a few cases (like hibernate-jpa-2.x-api) also artifact ids. HSQLDB must be updated to org.hsqldb:hsqldb version 2.3.2 and later, but this is no big deal. I will implement it in the next release.

Supporting new JPA 2.1 features is much more work.


Now a small side note. When posting links to jumpshare an other external resources, please clearly state the license or a legal status of the linked resource. I will consult pro bono only on sources which could be safely added as tests or samples to the project in the benefit of all users.

这篇关于将hyperjaxb3升级到jpa 2.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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