Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

java - Hibernate 3.5.x: NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval

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>

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...