Detailed Error stack information:
Org.hibernate.hibernateexception:a collection with cascade= "All-delete-orphan"is no longer referenced by the owning entity instance:xx.xx.TempItem.tempItemCats at Org.hibernate.engine.Collec Tions.processdereferencedcollection (Collections.java:119) at Org.hibernate.engine.Collections.processUnreachableCollection (Collections.java:62) at Org.hibernate.event.def.AbstractFlushingEventListener.flushCollections ( Abstractflushingeventlistener.java:241) at Org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions ( Abstractflushingeventlistener.java:100) at Org.hibernate.event.def.DefaultFlushEventListener.onFlush (Defaultflusheventlistener.java:49) at Org.hibernate.impl.SessionImpl.flush (Sessionimpl.java:1028) at Org.hibernate.impl.SessionImpl.managedFlush (Sessionimpl.java:366) at Org.hibernate.transaction.JDBCTransaction.commit (Jdbctransaction.java:137) at Org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit ( Hibernatetransactionmanager.java:656) at Org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit ( Abstractplatformtransactionmanager.java:754) at Org.springframework.transaction.support.AbstractPlatformTransactionManager.commit ( Abstractplatformtransactionmanager.java:723) at Org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning ( Transactionaspectsupport.java:393) at Org.springframework.transaction.interceptor.TransactionInterceptor.invoke (Transactioninterceptor.java: 120) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (Reflectivemethodinvocation.java: 172) at Org.springframework.aop.framework.JdkDynamicAopProxy.invoke (Jdkdynamicaopproxy.java:202) at $Proxy 65.save (Unknown Source)
Solution principle:
?
1 |
如果是 all - delete -orphan ,那个集合不能用setXXX(List) ,只能用 getXXX(). add () |
Instance code:
?
1 2 3 4 |
修改前:tempItem.setTempItemCats( set ); 修改后: tempItem.getTempItemCats().clear(); tempItem.getTempItemCats().addAll( set ); |