解决org.hibernate.NonUniqueObjectException的问题
不知道是不是之前处理懒加载的问题对session工厂进行了处理,导致了之前没有问题的地方出现了错误.
当修改班级操作时出现了错误
前端错误信息
后台处理以及报错信息
16:37:36,034 ERROR ExceptionMappingInterceptor:38 - a different object with the same identifier value was already associated with the session: [cn.peiying.domain.Classes#128]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.peiying.domain.Classes#128]
org.springframework.dao.DuplicateKeyException: a different object with the same identifier value was already associated with the session: [cn.peiying.domain.Classes#128]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.peiying.domain.Classes#128]
出现这个异常的原因:
Hibernate 增删改在 session 中已存在相同 OID(主键) 的对象。比如,先删除,后插入。
这就会报上面的错误。
原来是因为在Hibernate中同一个session内,如果已经有一个对象已经是持久化状态(load进来等),现在构造一个新的PO,和前一个持久化对象拥有相同的持久化标识(identifier),在update的时候,就会抛这个错误。
解决方法
1.不要重新new一个对象,使用load的对象对他进行更改值。
2.如果是hibernate3以上,可以使用session.merge()方法
3.把session中同标识的对象移出(session.evict(user1)),使他成为脱管的状态,然后user2就可以update了
this.getHibernateTemplate().getSessionFactory().getCurrentSession().clear();加上这行代码清除session后,执行通过
解决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 ...
- org.hibernate.NonUniqueObjectException 原因及解决办法
问题 使用hibernate更新对象时,出现如下错误: org.hibernate.NonUniqueObjectException: a different object with the same ...
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread---------程序报错
今天遇到了这个问题: org.hibernate.NonUniqueObjectException: a different object with the same identifier value ...
- opensessioninviewFilter导致org.hibernate.NonUniqueObjectException
起因: 公司业务需求,增加了一个新的数据源,增加之后,起初一切正常,但是发现后台管理系统所有Ajax请求获取信息没有问题,但是涉及到保存操作就抛出异常. 异常: org.hibernate.NonUn ...
- org.hibernate.NonUniqueObjectException
错误如下: 2017-3-29 15:17:52~ERROR~org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV ...
- atitit. 解决org.hibernate.SessionException Session is closed
atitit. 解决org.hibernate.SessionException Session is closed #--现象:: org.hibernate.SessionException ...
- hibernate异常:org.hibernate.NonUniqueObjectException
异常:org.hibernate.NonUniqueObjectException 提示:a different object with the same identifier value was a ...
- 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 ...
随机推荐
- MyEclipse10.6/Eclipse4.2 集成 flash builder 4.6
MyEclipse10.6/Eclipse4.2 集成 flash builder 4.61. 安装 Myeclipse10.6 或 Eclipse 4.2 以及 Flash builder 4.6 ...
- day1--心得
info = ''' --------------------info of %s---------------- name: %s age: %s job: %s ----------------- ...
- DRF之注册器响应器分页器
概要 url注册器 响应器 分页器 url注册器 通过DRF的视图组件,数据接口逻辑被我们优化到最剩下一个类,接下来,我们使用DRF的url控制器来帮助我们自动生成url,使用步骤如下: 第一步:导入 ...
- http://www.jb51.net/list/list_233_2.htm(导航: 首页 >> 软件编程 >> Android)
日期:2015-04-24理解Android中Activity的方法回调 日期:2015-04-24Android获取手机通讯录.sim卡联系人及调用拨号界面方法 日期:2015-04-24And ...
- MapReduce文件切分个数计算方法
转自:http://www.crazyant.net/1423.html Hadoop的MapReduce计算的第一个阶段是InputFormat处理的,先将文件进行切分,然后将每个切分传递给每个Ma ...
- 开启mysql远程访问
一.登陆mysql以后执行以下命令: GRANT ALL ON *.* TO username@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; FLUS ...
- LibEvent代码阅读--多缓冲区和零拷贝技术
http://blog.chinaunix.net/uid-20937170-id-4827550.html
- Color the ball (线段树的区间更新问题)
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色.但 ...
- 一次 Mysql 字符集的报错,最后让我万马奔腾!!!
wuba---深圳---龙岗周边----3000元--------- wuba---深圳---龙岗周边----5000元--------- wuba---深圳---龙岗周边----8000元----- ...
- 让IE10等支持classList2.0
chrome24+, firesfox26+起支持classList2.0,即让它同时添加或删除多个类名, toggle方法支持第2个参数,用于强制添加或删除 var div = document.c ...