org.hibernate.NonUniqueObjectException
来源:互联网 发布:淘宝怎么提高销量2016 编辑:程序博客网 时间:2024/05/21 10:01
使用hibernate进行更新操作时,首先调用了findById方法获取要修改的对象,此时session没有被关闭,接着重新创建一个对象,将要修改的属性值赋值给这个对象。调用修改方法抛出如下异常:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
原因:在session缓存中已经存在一个与当前传递进来的修改对象具有相同标识符(主键)的对象。Hibernate的机制是只能存在一个具有唯一标示的对象,否则增删改就会出错。
解决办法:
1:在使用过滤器/拦截器时,每次开启session,操作后就关闭session。
2:session.evict(Object object),从缓存中清除指定的对象。
3:session.clear(),是将session缓存中的对象全部清除,杀伤面太大了,不建议使用。
0 0
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException学习
- org.hibernate.NonUniqueObjectException 问题
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException解决方法
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException
- org.hibernate.NonUniqueObjectException异常解决方法
- org.hibernate.NonUniqueObjectException异常解决方法
- hibernate 保存出错:org.hibernate.NonUniqueObjectException
- 出现 org.hibernate.NonUniqueObjectException 错误的解决方法
- 异常org.hibernate.NonUniqueObjectException及其解决
- org.hibernate.NonUniqueObjectException 个人的解决办法
- 使用Koa2进行Web开发(二)静态文件与路由
- 青蛙跳台问题
- 题目1377:缓变序列
- SQL Server中行列转换 Pivot UnPivot
- Tips on non-standard evaluation in R
- org.hibernate.NonUniqueObjectException
- 基于Opencv平台开发的程序在其它电脑上独立运行
- CSU 1898: 复盘拉火车
- 【LeetCode】Convert Sorted Array to Binary Search Tree 解题报告
- label大小变换后,位置依然窗体居中
- swustoj Aconly时间戳(0275)
- 开源265 IP
- 分治尝试A
- Android源码bootable解析之bootloader LK(little kernel)