a different object with the same identifier value was already associated with the session。
来源:互联网 发布:四库全书数据库 编辑:程序博客网 时间:2024/05/17 07:14
[DH-OFFICE] 2013-06-16 23:50:30 ERROR [http-8080-5] NewsAction.save(128) | a different object with the same identifier value was already associated with the session: [com.sencloud.dh.oa.model.info.News#10060]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.sencloud.dh.oa.model.info.News#10060]
今天遇到这个问题: 可以通过下面的方式解决。
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)
以上两中异常经常出现在一对多映射和多对多映射中
- 解决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错误
- 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
- 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错误
- 解决a different object with the same identifier value was already associated with the session错误
- HibernateSystemException: 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
- 解决a different object with the same identifier value was already associated with the session错误
- Web 开发人员需知的 Web 缓存知识
- 《GOF设计模式》—观察者(OBSERVER)—Delphi源码示例:图形用户界面工具箱
- 心理学分析
- 大话数据结构之二:算法
- “开源”是什么,能吃吗?
- a different object with the same identifier value was already associated with the session。
- 笔记:Vmware安装提示The MSI failed
- File各种类操作文件、文件夹
- Passing …(rest) parameters between functions
- JQuery实现iframe自适应高度
- 自考*时间管理*压力
- Objective-C的self.用法的一些总结
- UIScrollView 原理详解
- fedora16 Samba配置