javax.persistence.OneToMany.orphanRemoval()Z

Spring3.0 + Hibernate3.5: 
启动服务器报: 
Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z 
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1830) 
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:762) 
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:726) 
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:636) 
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:359) 
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206) 
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
... 71 more 

 

1.在hibernate3.5之前,我们运用hibernate开发J2EE项目通常会引以下几个jar包: 
hibernate核心包:hibernate3.jar 
持久化:ejb3-persistence.jar 
则javax.persistence.OneToMany.class就在ejb3-persistence.jar中。 

2.在hibernate3.5及其以后,运用hibernate开发J2EE项目通常会引以下几个jar包: 
hibernate核心包:hibernate3.jar 
持久化:hibernate-jpa-2.0-XXX.jar 
hibernate-jpa-2.0-XXX.jar中已将包含了ejb3-persistence.jar所有类库和其他一些扩展,固然javax.persistence.OneToMany.class也就在hibernate-jpa-2.0-XXX.jar中了。所以当我们从3.5以下版本上级到3.5以上版本时,很容易出现不知道哪些jar包该保留哪些该删掉,因而两个jar包同时存在,出现了这个冲突异常。 

3.其实持久化并不是只有ejb3-persistence.jar和hibernate-jpa-2.0-XXX.jar提供,Java EE(注意:是Java EE,并不是J2ee,J2ee在1.4以后就命名为Java EE,而且新增了很多类库)核心类库同样也提供了javax.persistence类库,当你的项目hibernate导入的jar都正常后仍旧出现冲突异常,那么你就要考虑是不是你引入的其他类库导致了这个异常。比如Java EE5及其以后的核心类库。 

你可能感兴趣的:(java)