解决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 ...
随机推荐
- MySQL 性能测试经验
一.背景 近期在进行资源调度管理平台的重构工作,其中的Resource/Property数据库设计,在没有更加优化的方案前,打算沿用当前平台的数据库结构:这就需要对当前平台的数据库结构进行剖析研究,并 ...
- chart左侧
左侧单位 Chart1.Axes.Left.Minimum := ; Chart1.Axes.Left.Maximum := Series1.YValues.MaxValue * ; Chart1.A ...
- Python 小练习一
1.如果同一个ip地址60s之内访问超过200次,那么就把ip加入黑名单 需求分析: 1.60s读一次文件 2.分割,取第一个元素,ip地址 3.把所有ip加入到一个list里面,如果ip次数超过20 ...
- java游戏制作之水果忍者
水果忍者的原理很简单,主要就是采用随机的方式是画面上面出现水果. package Fruitninja; import java.awt.Dimension; import java.awt.Grap ...
- 当property遇上category
[当property遇上category] @property可以在类定义中,以及extension定义中使用,编译器会自动为@property生成代码,并在变量列表(ivar_list_t)中添加相 ...
- ORA-01940:无法删除当前已链接的用户
(1)查看用户的连接状况 select user name, sid, serial# from v$session; (2)找到要删除用户的sid,和serial,并删除 例如要删除用户nc633t ...
- selenium2 定位 窗体切换等等 (二)
定位用的html素材有两个 demo.html <html> <head> <title>UI Automation Testing</title> & ...
- zend studio 字体大小修改,默认编码设置
zend studio的字体感觉很小,很多用户不是很适应,修改方法如下: 第一步:进入设置窗口 windows -> preferences 第二步:进入修改字体的选项卡. Gene ...
- 反射01 Class类的使用、动态加载类、类类型说明、获取类的信息
0 Java反射机制 反射(Reflection)是 Java 的高级特性之一,是框架实现的基础. 0.1 定义 Java 反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对 ...
- hadoop 2.7.3 (hadoop2.x)使用ant制作eclipse插件hadoop-eclipse-plugin-2.7.3.jar
为了做mapreduce开发,要使用eclipse,并且需要对应的Hadoop插件hadoop-eclipse-plugin-2.7.3.jar,首先说明一下,在hadoop1.x之前官方hadoop ...