码迷,mamicode.com
首页 > 系统相关 > 详细

org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:

时间:2014-06-16 07:01:08      阅读:823      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

详细错误堆栈信息:

bubuko.com,布布扣
org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: xx.xx.TempItem.tempItemCats
    at org.hibernate.engine.Collections.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 $Proxy65.save(Unknown Source)
bubuko.com,布布扣

解决原理:

1
如果是 all-delete-orphan ,那个集合不能用setXXX(List) ,只能用 getXXX().add()

实例代码:

1
2
3
4
修改前:tempItem.setTempItemCats(set);
修改后:
    tempItem.getTempItemCats().clear();
    tempItem.getTempItemCats().addAll(set);

  

  

 

org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:,布布扣,bubuko.com

org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/tq03/p/3783928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!