日期:2014-05-17  浏览次数:20609 次

ssh 中 级联删除问题 【求助】
下面是一个java project的设置:
<set name="orders" cascade="all" inverse="true">
<key column="customer_id"></key> 
<one-to-many class="com.test.Order"/>
</set>

<many-to-one name="customer" column="customer_id" class="com.test.Customer">
</many-to-one>

这个project中保存、删除customer时都可以同时保存、删除关联的order。

下面是一个web project的设置:
<list name="items" cascade="all" inverse="true" lazy="true">
<key column="question_id"></key> 
<index column="item_index_"></index>
<one-to-many class="com.test.bean.Item"/>
</list>

<many-to-one name="question" column="question_id" class="com.test.bean.Question">
</many-to-one>

这个project中可以实现级联保存,但是在删除question时就会出异常,希望哪位高手能帮解答下。
异常如下:
java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`poll`.`items`, CONSTRAINT `FK_QUESTION_ID` FOREIGN KEY (`QUESTION_ID`) REFERENCES `questions` (`ID`))
com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1269)
com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:955)
org.apache.commons.dbcp.DelegatingPreparedStatement.executeBatch(DelegatingPreparedStatement.java:203)
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:172)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy9.delete(Unknown Source)
com.test.action.DeleteQuestionAction.execute(DeleteQuestionAction.java:44)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440)
com.opensymphony.xwork2.De