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时,一般是因为在hibernate中同一个session里面有了两个相同标识但是是不同实体。
(原因:
因为在向数据库中修改数据时,先查询了一次。存在同一试题类型的不同对象中。这样就会报这样的错。
我的解决是:
将从页面得到的要修改的值,赋值到查询得到的实体对象,修改写入时,使用查询的那个实体。
)
网上所有的解决方案,包括:
(1)使用session.clean(),如果在clean操作后面又进行了saveOrUpdate(object)等改变数据状态的操作,有可能会报出"Found two representations of same collection"异常。
(2)使用session.refresh(object),当object不是数据库中已有数据的对象的时候,不能使用 session.refresh(object)因为该方法是从hibernate的session中去重新取object,如果session中没有这个对象,则会报错所以当你使用saveOrUpdate(object)之前还需要判断一下。
(3)session.merge(object),Hibernate里面自带的方法,推荐使用。
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错误
[转]解决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错误
1.a different object with the same identifier value was already associated with the session. 错误原因:在h ...
- 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"?> ...
- 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 ...
- 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 ...
- 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:
保存实体异常 https://blog.csdn.net/zzzz3621/article/details/9776539 org.hibernate.NonUniqueObjectException ...
- 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: [com.elec.domain.ElecCommonMsg#297e35035c28c368015c28c3e6780001]
使用hibernate更新数据时,报错 Struts has detected an unhandled exception: Messages: a different object with th ...
随机推荐
- awk 的使用
awk [-F field-separator] 'commands' input-file(s) 其中,commands 是真正awk命令,[-F域分隔符]是可选的.input-file(s) 是待 ...
- 如何提高ASP.NET页面载入速度的方法
前言 本文是我对ASP.NET页面载入速度提高的一些做法,这些做法分为以下部分: 1.采用 HTTP Module 控制页面的生命周期. 2.自定义Response.Filter得到输出流stream ...
- HoloLens模拟器仿真器与文档现已向开发者们开放
HoloLens仿真器与文档现已向开发者们开放 直接上链接吧:http://mt.sohu.com/20160301/n438961462.shtml
- 虚拟现实外包公司— VR开发编辑器意义重大 印证VR不仅服务于用户
三大引擎制造商 Unity Technologies .Epic Games 和Crytek 讨论在自家产品中添加附件,方便开发商在虚拟现实中创作游戏.这会对许多人造成影响,特别是早已进入虚拟现实的先 ...
- nodeJS---express4+passport实现用户注册登录验证
网上有很多关于passport模块使用方法的介绍,不过基本上都是基于express3的,本文介绍在express4框架中使用passport模块. 前言 passport是一个功能单一,但非常强大的一 ...
- 【DNS】简单聊聊DNS如何工作
随便聊聊 我们知道,网络上传输的数据包是一层一层的包起来的,典型的是mac地址层,ip层,tcp/udp层,应用层数据 这么几个层,那用户在浏览器中打开www.baidu.com数据包如何传到baid ...
- 用git管理自己读的书
福昕阅读器,可以方便地做书签和备注.使用git去管理图书和示例代码,一方面能够很好地保存这些资料,方便查找:另外一方面,无论在家,还是在公司,都能很好地同步自己学习的进度. 福昕阅读器5(视图--&g ...
- CSS盒子模型与box-sizing
今天在学习的时候偶然看到一张图片: 我瞬间瞪大了眼睛:width和height竟然不包括padding和border!! 过去所学知识有问题!在我的印象里,width应该是包含padding和bord ...
- iOS UIButton单双击处理响应不同的方法
//显示目标 双击显示当前用户坐标位置 UIButton * btnShowDistination = [[UIButton alloc]initWithFrame:CGRectMake(, SCRE ...
- zzz
开放平台(TOP)的API是基于HTTP协议来调用的,开发者(ISV)可以直接使用TOP提供的官方SDK(支持多种语言,包含了请求的封装,签名加密,响应解释,性能优化等)来调用,也可以根据TOP的协议 ...