zoukankan      html  css  js  c++  java
  • org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:

    详细错误堆栈信息:

    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)

    解决原理:

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

    实例代码:

    修改前:tempItem.setTempItemCats(set);
    修改后:
    	tempItem.getTempItemCats().clear();
    	tempItem.getTempItemCats().addAll(set);
    

      

      

  • 相关阅读:
    DNF(一.YUM已死,DNF代之)
    cmd中运行python文件,并带参数
    python中dict[key] 存在key,但是报错:KeyError
    回测指标计算
    python进行excel操作
    myquant平台搭建及使用
    远程连接mongodb时,27017端口连接不上的解决办法
    python---urllib模块
    python---socket模块
    状态模式
  • 原文地址:https://www.cnblogs.com/tq03/p/3783928.html
Copyright © 2011-2022 走看看