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 ...
随机推荐
- set类型
set 集合 是string类型的无序集合.我们可以对集合去交集 并集 差集 sadd 添加元素 不允许有重复的值 smembers 查看元素中的值 srem 删除set中的值
- 2017-06-20 (pwd ls cd)
pwd pwd 显示当前所在的位置 pwd -P 如果是链接文件,显示链接文件所指的位置 ls ls 查询目录中的内容 ls -a 显示所有的文件,包含隐藏的文件 -l 显示详细的信息 ...
- php的print_r第二个参数是true有啥用啊
print_r(); 第二个参数 为true时 返回值 而不显示. echo ,print,print_r的区别 echo ,print的区别在于echo 可以输出多个变量值,而print只有一个变量 ...
- CentOS 通过yum来升级php到php5.6
在文章中,我们将展示在centOS系统下如果将php升级到5.6,之前通过yum来安装lamp环境,直接升级的话,提示没有更新包,也就是说默认情况下php5.3.3是最新 1.查看已经安装的php版本 ...
- 【转】shell学习笔记(七)——流程控制之while
while do done, until do done (不定回圈) 当 condition 条件成立时,就进行回圈,直到 condition 的条件不成立才停止 while [condition] ...
- 【转】rinex
RINEX(Receiver INdependent Exchange)格式是与接收机无关的数据交换格式,该格式采用文本文件存储数据,数据记录格式与接收机的制造厂商和具体型号无关.RINEX ...
- Jmeter性能测试,新手上路篇
1. JMeter简介 Apache JMeter是Apache组织开发的基于Java的压力测试工具.用于对软件做压力测试,它最初被设计用于Web应用测试,但后来扩展到其他测试领域. 它可以用于测试静 ...
- snowflake分布式唯一id c#实现
snowflake算法 snowflake是Twitter开源的分布式ID生成算法,结果是一个long型的ID.其核心思想是:使用41bit作为毫秒数,10bit作为机器的ID(5个bit是数据中心, ...
- 如何使用Python读取大文件
背景 最近处理文本文档时(文件约2GB大小),出现memoryError错误和文件读取太慢的问题,后来找到了两种比较快Large File Reading 的方法,本文将介绍这两种读取方法. 准备工作 ...
- BZOJ 3456: 城市规划 [多项式求逆元 组合数学 | 生成函数 多项式求ln]
3456: 城市规划 题意:n个点组成的无向连通图个数 以前做过,今天复习一下 令\(f[n]\)为n个点的无向连通图个数 n个点的完全图个数为\(2^{\binom{n}{2}}\) 和Bell数的 ...