Hibernate 3.5.x: NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval [英] Hibernate 3.5.x: NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval

查看:40
本文介绍了Hibernate 3.5.x: NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试升级到 Hibernate 3.5.3-FINAL.

在运行我的单元测试时,我现在收到以下异常:

java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z在 org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1837)

我的类路径包含以下 JAR:

来自休眠区:

antlr-2.7.6.jarcommons-collections-3.1.jardom4j-1.6.1.jarjavassist-3.9.0.GA.jarjta-1.1.jarslf4j-api-1.5.8.jarcglib-2.2.jarhibernate-jpa-2.0-api-1.0.0.Final.jarhibernate3.jar

其他罐子:

blazeds-common-3.2.0.3978.jarblazeds-core-3.2.0.3978.jarblazeds-opt-3.2.0.3978.jarblazeds-proxy-3.2.0.3978.jarblazeds-remoting-3.2.0.3978.jarcommons-lang-2.3.jardbunit-2.4.7.jarejb3-persistence.jar//注意,我试过排除这个,但我得到了不同的错误番石榴-r05.jarhsqldb-1.8.0.7.jarjunit-4.1.jarlambdaj-2.0-with-dependencies.jarlog4j-1.2.14.jarmockito-all-1.8.0.jar持久化api-1.0.jarspring-security-core-2.0.0.jarspring.jarsqljdbc.jar

我对此进行了研究,并且我找到答案表明我的网络服务器必须符合 JPA2:

<块引用>

不幸的是,如果您的应用服务器是不符合 JPA 2,您可能会运气不好

这个项目是一个库,而不是一个网络服务器项目.(虽然最终会部署到网络服务器上,但我只是在这里运行单元测试)

我错过了什么?

作为旁注,每次升级 Hibernate 时,我都会发现自己花费数小时研究 MethodNotFoundExceptionClassNotFoundException 的冲突 jar,这非常令人沮丧.一定有更简单的方法吗?

我确信,随着他们宣布将模块合并回一个单一的核心项目,这些冲突会消失吗?

解决方案

正如 Timo 所指出的,删除 persistence-api-1.0.jar.

以防万一,这里是我正在使用的依赖项:

<前>org.hibernate:hibernate-entitymanager:jar:3.5.3-Final:compile+- org.hibernate:hibernate-core:jar:3.5.3-Final:compile|+- antlr:antlr:jar:2.7.6:compile|+- commons-collections:commons-collections:jar:3.2:compile|+- dom4j:dom4j:jar:1.6.1:compile||- xml-apis:xml-apis:jar:1.0.b2:compile|- javax.transaction:jta:jar:1.1:compile+- org.hibernate:hibernate-annotations:jar:3.5.3-Final:compile|- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile+- cglib:cglib:jar:2.2:compile|- asm:asm:jar:3.1:compile+- javassist:javassist:jar:3.9.0.GA:compile- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile

我从我的 pom.xml 中的这个单一声明中获取它们:

<依赖><groupId>org.hibernate</groupId><artifactId>hibernate-entitymanager</artifactId><version>3.5.3-Final</version></依赖>

这应该以某种方式回答你放纵的咆哮(如果我改写:使用 Maven - 或者知道你在做什么).

I'm trying to upgrade to Hibernate 3.5.3-FINAL.

When running my unit tests, I now receive the following exception:

java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z   
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1837)

My classpath contains the following JAR's:

From the hibernate dist:

antlr-2.7.6.jar
commons-collections-3.1.jar
dom4j-1.6.1.jar
javassist-3.9.0.GA.jar
jta-1.1.jar
slf4j-api-1.5.8.jar

cglib-2.2.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
hibernate3.jar

Other jars:

blazeds-common-3.2.0.3978.jar
blazeds-core-3.2.0.3978.jar
blazeds-opt-3.2.0.3978.jar
blazeds-proxy-3.2.0.3978.jar
blazeds-remoting-3.2.0.3978.jar
commons-lang-2.3.jar
dbunit-2.4.7.jar
ejb3-persistence.jar // Note, I've tried excluding this, but I get different errors
guava-r05.jar
hsqldb-1.8.0.7.jar
junit-4.1.jar
lambdaj-2.0-with-dependencies.jar
log4j-1.2.14.jar
mockito-all-1.8.0.jar
persistence-api-1.0.jar
spring-security-core-2.0.0.jar
spring.jar
sqljdbc.jar

I've researched this, and I find answers that state my webserver must be JPA2 Compliant:

Unfortunately if your app server is not JPA 2 compliant, you are likely to be out of luck

This project is a library, not a webserver project. (Although it is eventually deployed to a webserver, I'm simply running unit tests here)

What am I missing?

<indulgent_rant>

As a sidenote, it's very frustrating that every time I upgrade Hibernate, I find myself spending hours researching conflicting jars for MethodNotFoundException or ClassNotFoundException's. There must be a simpler way?

I thought for sure that with the announcement they were merging the modules back to a single core project, that these conflicts would go away?

</indulgent_rant>

解决方案

As pointed out by Timo, remove persistence-api-1.0.jar.

Just in case, here are the dependencies I'm using:

org.hibernate:hibernate-entitymanager:jar:3.5.3-Final:compile
+- org.hibernate:hibernate-core:jar:3.5.3-Final:compile
|  +- antlr:antlr:jar:2.7.6:compile
|  +- commons-collections:commons-collections:jar:3.2:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  |  - xml-apis:xml-apis:jar:1.0.b2:compile
|  - javax.transaction:jta:jar:1.1:compile
+- org.hibernate:hibernate-annotations:jar:3.5.3-Final:compile
|  - org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
+- cglib:cglib:jar:2.2:compile
|  - asm:asm:jar:3.1:compile
+- javassist:javassist:jar:3.9.0.GA:compile
- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile

I'm getting them from this single declaration in my pom.xml:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>3.5.3-Final</version>
</dependency>

This should somehow answer your indulgent rant (if I rephrase: use Maven - or know what you're doing).

这篇关于Hibernate 3.5.x: NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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