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 with the session。
原因:在hibernate中同一个session里面有了两个相同标识但是是不同实体。通常来说,使用session的merge(object)便可以解决。
但也有其他令几种方式供参考:
1、a different object with the same identifier value was already associated with the session。
错误原因:在hibernate中同一个session里面有了两个相同标识但是是不同实体。
解决方法一:session.clean()
PS:如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。
解决方法二:session.refresh(object)
PS:当object不是数据库中已有数据的对象的时候,不能使用session.refresh(object)因为该方法是从hibernate的session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。
解决方法三:session.merge(object)
PS:Hibernate里面自带的方法,推荐使用。
2、Found two representations of same collection
错误原因:见1。
解决方法:session.merge(object)
以上两中异常经常出现在一对多映射和多对多映射中。
Hibernate Error: 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 already associated with the session:
保存实体异常 https://blog.csdn.net/zzzz3621/article/details/9776539 org.hibernate.NonUniqueObjectException ...
- 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 ...
- 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 ...
- hibernate 异常a different object with the same identifier value was already associated with the session
在使用hibernate的时候发现了一个问题,记录一下解决方案. 前提开启了事务和事务间并无commit,进行两次save,第二次的时候爆出下面的异常a different object with t ...
- rg.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
原先跑TEST CASE的时候没有出错 但是跑到整个程序里面,除了这个问题, 网上也找了下资料,说是用merge之类的可以解决,因为你这个update的obj和session里面的不用,所以导致此问题 ...
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread---------程序报错
今天遇到了这个问题: org.hibernate.NonUniqueObjectException: a different object with the same identifier value ...
- 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"?> ...
- Hibernate更新数据报错:a different object with the same identifier value was already associated with the session: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]
使用hibernate更新数据时,报错 Struts has detected an unhandled exception: Messages: a different object with th ...
- a different object with the same identifier value was already associated with the session解决方案
org.springframework.orm.hibernate3.HibernateSystemException: a different ]; nested exception ] at or ...
随机推荐
- python3 第五章 - 什么是变量、运算符、表达式
在读这一章时,运算符的内容比较多,不要去死记.现在记不住也没有关系,现在只要有这个印象.在后面的学习中,会慢慢加深理解,在理解中去记就容易得多了 1.变量 什么是变量?通俗的讲,就是存储在内存中可以变 ...
- greedy算法(python版)
greedy算法的核心思想是首先计算覆盖面大的部分,然后依次寻找其他覆盖面最大的部分.该算法的使用场景就像他的名字一样,当符合贪婪属性的时候就可以考虑. states_needed = set(['北 ...
- Cannot create an instance of OLE DB provider “OraOLEDB.Oracle” for linked server "xxxxxxx".
在SQL SERVER 2008 R2下用Windows 身份认证的登录名创建了一个访问ORACLE数据库的链接服务器xxxxx,测试成功,木有问题,但是其它登录名使用该链接服务器时,报如下错误: 消 ...
- MySQL--REPEATABLE-READ隔离级别下读取到的“重复数据”
在MySQL中,使用MVCC来实现REPEATABLE-READ隔离级别,由于SELECT操作不会对数据加锁,其他回话可以修改当前回话所读取过的数据而不会被阻塞,因此读写不冲突. 在MVCC并发控制中 ...
- js结合方式:
1. 在页面中使用script标签,在标签中书写js代码.<head><script type="text/javascript"> alert(&q ...
- win7:你需要来自Administrators的权限才能对此文件进行修改的一个文件
win7:你需要来自Administrators的权限才能对此文件进行修改的一个文件 Posted on 2010-11-29 09:54 寒宵飞飞 阅读(36117) 评论(1) 编辑 收藏 新建一 ...
- c#控制WPF程序自动登录(Automation方式实现)
说明:winForm窗体,可以通过win32接口dll的findWindow之类的函数来实现查找winform窗口,mfc窗口等. 但是wpf却是不实用这些,可以靠automation方式来进行操作. ...
- Centos6.5离线安装lsb_release
参考 http://www.linuxfromscratch.org/blfs/view/systemd/postlfs/lsb-release.html首先在其他电脑下载lsb_release源码地 ...
- JVM学习(一)
一.gc日志查看与分析 在sever端的run.xml中run和debug中加入如下参数: <jvmarg value="-XX:+PrintGCDateStamps"/&g ...
- POJ 3348 Cows [凸包 面积]
Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9022 Accepted: 3992 Description ...