Reputation: 3224
I have Spring MVC App integrated with Hibernate. Everything was OK until I use @OneToMany annotation... I'm getting the following error:
Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1912)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:805)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:745)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:134)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 81 more
Here's my WEB-INF/lib contents:
aopalliance-1.0.jar
commons-beanutils-1.8.3.jar
commons-collections-3.2.1.jar
commons-digester-2.1.jar
commons-logging-1.1.1.jar
dom4j-1.6.1.jar
h2-1.3.164.jar
hibernate-commons-annotations-3.2.0.Final.jar
hibernate-core-3.6.9.Final.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
javassist-3.12.1.GA.jar
log4j-1.2.16.jar
slf4j-api-1.6.4.jar
slf4j-log4j12-1.6.4.jar
spring-aop-3.1.1.RELEASE.jar
spring-asm-3.1.1.RELEASE.jar
spring-beans-3.1.1.RELEASE.jar
spring-context-3.1.1.RELEASE.jar
spring-core-3.1.1.RELEASE.jar
spring-expression-3.1.1.RELEASE.jar
spring-hibernate3-2.0.8.jar
spring-jdbc-3.1.1.RELEASE.jar
spring-orm-3.1.1.RELEASE.jar
spring-tx-3.1.1.RELEASE.jar
spring-web-3.1.1.RELEASE.jar
spring-webmvc-3.1.1.RELEASE.jar
spring-webmvc-3.1.1.RELEASE-sources.jar
tiles-api-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
I saw that for some people helped ejb3-persitence.jar removing but my classpath doesn't contain that jar. There's everythinh OK if I run this app under other application servers like JBoss or Glassfish.
Upvotes: 0
Views: 1229
Reputation: 15876
That class is provided in several jar files so you need to ensure that your application is using the correct one.
First you need to workout which one it is using. Try and remove it from your WEB-INF/lib folder and if you still get the same error then it means it is loaded from somewhere else.
Also try and copy it to $TOMCAT_HOME/lib as a test to see what happens.
If you are using Eclipse try and verify the JRE/JDK you are using because the javaee-api-5 also includes these classes. It might also be worth ensuring that the javaee-api is not being included when it is loaded by Tomcat.
Examples of jar files to that can cause conflicts with your hibernate-jpa jar file is given below (could have different version numbers):
persistence.jar
toplink-essentials.jar
ejb3-persistence-1.0.1.GA.jar
ejb3-persistence-1.0.2.GA.jar
ejb3-persistence-3.3.2.Beta1.jar
geronimo-jpa_1.0_spec-1.1.2.jar
geronimo-jpa_3.0_spec-1.0.jar
geronimo-jpa_3.0_spec-1.1.1.jar
geronimo-jpa_3.0_spec-1.1.jar
persistence-api-1.0.jar
geronimo-jpa_2.0_spec-1.0-PFD2.jar
geronimo-jpa_3.0_spec-1.0-M1.jar
glassfish-persistence-api-b32g.jar
javaee-api-5.0-1.jar
javaee-api-5.0-2.jar
openjpa-all-2.0.0-M3.jar
openejb-itests-standalone-client-3.0.1.jar
openejb-itests-standalone-client-3.0.jar
openejb-itests-standalone-client-3.1.1.jar
openejb-itests-standalone-client-3.1.jar
The issue is definitely caused by conflicts with the jar files you just need to try different situations to work out exactly where the conflict is.
Upvotes: 2