不知道是不是之前处理懒加载的问题对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的问题的更多相关文章

  1. 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 ...

  2. org.hibernate.NonUniqueObjectException 原因及解决办法

    问题 使用hibernate更新对象时,出现如下错误: org.hibernate.NonUniqueObjectException: a different object with the same ...

  3. org.hibernate.NonUniqueObjectException: a different object with the same identifier value was alread---------程序报错

    今天遇到了这个问题: org.hibernate.NonUniqueObjectException: a different object with the same identifier value ...

  4. opensessioninviewFilter导致org.hibernate.NonUniqueObjectException

    起因: 公司业务需求,增加了一个新的数据源,增加之后,起初一切正常,但是发现后台管理系统所有Ajax请求获取信息没有问题,但是涉及到保存操作就抛出异常. 异常: org.hibernate.NonUn ...

  5. org.hibernate.NonUniqueObjectException

    错误如下: 2017-3-29 15:17:52~ERROR~org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV ...

  6. atitit. 解决org.hibernate.SessionException Session is closed

    atitit. 解决org.hibernate.SessionException Session is closed   #--现象:: org.hibernate.SessionException ...

  7. hibernate异常:org.hibernate.NonUniqueObjectException

    异常:org.hibernate.NonUniqueObjectException 提示:a different object with the same identifier value was a ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 转:Python正则表达式指南

    本文介绍了Python对于正则表达式的支持,包括正则表达式基础以及Python正则表达式标准库的完整介绍及使用示例.本文的内容不包括如何编写高效的正则表达式.如何优化正则表达式,这些主题请查看其他教程 ...

  2. srvctl和crs_start命令无法启动oracle RAC实例, 但sqlplus可以启动

    今天遇到一个奇怪问题,发现srvctl和crs_start命令无法启动Oracle RAC实例,但用sqlplus却可以正常启动.最终发现原因是在OCR中数据库的状态变成了disable,将此状态更改 ...

  3. krpano之语音介绍

    语音介绍:在每进入一个场景时,播放一段该场景的语音介绍. 制作步骤: 1.定义全局事件.在关闭场景时执行stopsounds(),在打开新场景时执行automusic(). <events on ...

  4. python学习——练习题(1)

    """ 题目:有四个数字:1.2.3.4,能组成多少个互不相同且无重复数字的三位数?各是多少? """ import itertools d ...

  5. HashMap与ConcurrentHashMap的区别(转)

    从JDK1.2起,就有了HashMap,正如前一篇文章所说,HashMap不是线程安全的,因此多线程操作时需要格外小心. 在JDK1.5中,伟大的Doug Lea给我们带来了concurrent包,从 ...

  6. 如何用CURL将文件下载到本地指定文件夹

    若直接调用下载文件的url有重定向,则需先调用第一个方法,获取到跳转后的url,才可直接下载.否则需要手动点击浏览器的下载确定按钮. 调用示例: $imgpath = "http://www ...

  7. Markdown使用简单示例(每一个使用对应一个实际的markdown语法)

    1.标题示例:通过"#"数量表示几级标题.(一共只有1~6级标题,1级标题字体最大) 标题一 #标题一 标题二 #标题二 标题三 ###标题三 标题四 ####标题四 标题五 ## ...

  8. SPQuery DateTime 类型查询

    使用SPQuery查询时间,默认查询会忽略 时分秒,只检查日期,如果要检查时间,则必须添加 IncludeTimeValue='TRUE' 格式如下: <Where>    <Gt& ...

  9. 【光速使用开源框架系列】图片加载框架ImageLoader

    [关于本系列] 最近看了不少开源框架,网上的资料也非常多,但是我认为了解一个框架最好的方法就是实际使用.本系列博文就是带领大家快速的上手一些常用的开源框架,体会到其作用. 由于作者水平有限,本系列只会 ...

  10. linux设置rsync+inotify实时同步文件

    linux设置rsync+inotify实时同步文件   应用场景: 同步接收方:test01 接收目录:/opt/software/test/a/ 同步发起方:test02 同步目录:/opt/so ...