org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [cn.ac.iscas.core.entity.pm.cm.CmPlanBaseline#]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.ac.iscas.core.entity.pm.cm.CmPlanBaseline#]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:)
at cn.ac.intec.entity.orm.impl.SessionImpl.saveOrUpdate(SessionImpl.java:)
at cn.ac.intec.entity.orm.impl.SessionImpl.insertOrUpdate(SessionImpl.java:)
at cn.ac.intec.entity.orm.impl.SessionImpl$$FastClassByCGLIB$$550f49cd.invoke(<generated>)

触发场景,解决方案:
1. show业务操作,开启一个session ,从中查出一些实体,这时某个实体是存在于session中的持久化对象。通过业务逻辑将此实体用于页面展示。此时这个session并未关闭。

2. 这时执行一步save业务逻辑,将上一步获得的实体id传回后台 。这时通过new的方式创建了一个临时对象,并且我将传回的id作为主键赋值给了临时对象。然后调用了session.save(obj); 方法 。。。抛出异常。

原因很简单,session中有2个oid一样的对象,hibernate不知道该让哪个持久化到库里。当时解决思路也很清晰,直接clear();清空一下 session缓存不就Ok了。但是clear打击面太广了(慎用!)。其他一些“无辜”对象也被杀掉,导致其他业务无法进行了。

后来在session中发现一个evict方法,“定点清除”对象缓存。这下就好了,先用传回来的id用get方法(其实这里用load方法也行反正都是从缓存中加载)获得session里的持久化实体,然后杀掉,再保存临时实体。没问题了。

a different object with the same identifier value was already associated with the session解决方案的更多相关文章

  1. a different object with the same identifier value was already associated with the session:

    hibernate操作: 实例化两个model类,更新时会提示  a different object with the same identifier value was already assoc ...

  2. [转]解决a different object with the same identifier value was already associated with the session错误

    1.a different object with the same identifier value was already associated with the session. 错误原因:在h ...

  3. a different object with the same identifier value was already associated with the session:错误;

    当出现a different object with the same identifier value was already associated with thesession时,一般是因为在h ...

  4. 解决a different object with the same identifier value was already associated with the session错误

    [转]解决a different object with the same identifier value was already associated with the session错误 这个错 ...

  5. hibernate中一种导致a different object with the same identifier value was already associated with the session错误方式及解决方法

    先将自己出现错误的全部代码都贴出来: hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> ...

  6. Hibernate Error: a different object with the same identifier value was already associated with the session

    在执行Hibernate的Update操作时,报错:a different object with the same identifier value was already associated w ...

  7. Exception 06 : org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session :

    异常名称: org.hibernate.NonUniqueObjectException: A different object with the same identifier value was ...

  8. org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:

    保存实体异常 https://blog.csdn.net/zzzz3621/article/details/9776539 org.hibernate.NonUniqueObjectException ...

  9. org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session异常解决办法

    org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread ...

随机推荐

  1. HTTP Client Performance Improvements

    HTTP Client Performance Improvements https://blogs.msdn.microsoft.com/webdev/2018/10/17/asp-net-core ...

  2. 如何通过eclipse查看、阅读hadoop2.4源码

    问题导读:1.官网src包下载包,能否直接使用?2.如何跟踪和查看hadoop源码? 此篇是从零教你如何获取hadoop2.4源码并使用eclipse关联hadoop2.4源码基础上的一个继续,上文其 ...

  3. 51nod 1347 旋转字符串

    S[0...n-1]是一个长度为n的字符串,定义旋转函数Left(S)=S[1…n-1]+S[0].比如S=”abcd”,Left(S)=”bcda”.一个串是对串当且仅当这个串长度为偶数,前半段和后 ...

  4. Java Garbage Collection

    在C/C++中,需要自己负责object的creation 和 destruction. 如果忘记了destruction, 就容易出现OutOfMemoryErrors. Java中会有GC直接处理 ...

  5. Kalman Filter

    本质是一种最优估计法.  核心是"预测"+"测量反馈". 一个视频: http://blog.sina.com.cn/s/blog_461db08c0102uw ...

  6. Huffman树的构造及编码与译码的实现

    哈夫曼树介绍 哈夫曼树又称最优二叉树,是一种带权路径长度最短的二叉树.所谓树的带权路径长度,就是树中所有的叶结点的权值乘上其到根结点的路径长度(若根结点为0层,叶结点到根结点的路径长度为叶结点的层数) ...

  7. 构建docker私有库

    前提: ip:     172.16.0.9 docker:   Version:  18.05.0-ce   1下载registry  docker pull registry   2 建库 将库像 ...

  8. hadoop之 hadoop用途方向

    hadoop是什么?Hadoop是一个开源的框架,可编写和运行分不是应用处理大规模数据,是专为离线和大规模数据分析而设计的,并不适合那种对几个记录随机读写的在线事务处理模式.Hadoop=HDFS(文 ...

  9. linux查找目录下的所有文件中是否含有某个字符串 (转)

    查找目录下的所有文件中是否含有某个字符串 find .|xargs grep -ri "IBM" 查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 find .|xar ...

  10. FPGA设计中的float

    在通常的设计中,不建议使用浮点数计算,因为浮点数计算会消耗FPGA大量的逻辑单元.但很多情况下,又需要使用浮点数进行计算提高精度. 所以需要有合适的方法计算浮点运算. 正常情况下FPGA只能以整形数据 ...