nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z

使用spring + hibernate annotations的@OneToMany 一对多双向关联后出现异常: 
java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z  
出现这种异常通常是由于Myeclipse的javaee.jar 版本较低,与Hibernate等自带的JPA出现了冲突。 

网上一些处理方法是删除项目里的 删除 建立web项目时自带的Javaee.jar,可是这样带来的后果是 httpServletRequest 等组件无法使用。 

直接用JDK1.6创建工程

<prop key="javax.persistence.validation.mode">none</prop>



	<bean id="sessionFactory"
		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">   
		<property name="dataSource" ref="dataSource" />
		<property name="hibernateProperties">
			<props>
				<prop key="javax.persistence.validation.mode">none</prop>
				<prop key="hibernate.dialect">${hibernate.dialect}</prop>
				<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
				<prop key="hibernate.format">${hibernate.format}</prop>
<!--  只要建立一个空的数据库 DDL就能根据实体类自动生成数据库表-->
				<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
			</props>
		</property>
  		<property name="packagesToScan">   
   			<list>   
    			<value>com.gaozhi.school.**.model</value><!-- 扫描注解方式的实体类,也就是model -->   
  			 </list>   
    	</property>  
	</bean>


你可能感兴趣的:(nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z)