不知道是不是之前处理懒加载的问题对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. 【phonegap】下载文件

    <!-- 打包的时候phonegap自己会添加这个文件--> <script type="text/javascript" charset="utf-8 ...

  2. shulti模块简述

    #-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import shutil shutil.copyfileobj('D:\\3. ...

  3. Node.js实用知识点

    本文介绍如何使用nodejs 简单的HttpServer 调试nodejs 基础路由 nodejs配置开发和生产环境 nodejs核心模块一览 express用法 文件I/O nodejs模块 nod ...

  4. java成神之——集合框架之ArrayList,Lists,Sets

    集合 集合种类 ArrayList 声明 增删改查元素 遍历几种方式 空集合 子集合 不可变集合 LinkedList Lists 排序 类型转换 取交集 移动元素 删除交集元素 Sets 集合特点 ...

  5. Windows nvidia显卡的设置方法

    1.直接右下角打开N卡控制面板托盘按钮,一般来说都是自动隐藏在小箭头里的,点开就可以显示隐藏的图标了.[插入图片“右下角小箭头”]2.开始菜单 - 控制面板 ,可以看到“显卡控制面板”这个选项,进去就 ...

  6. Python3.x 常用的新特性

    Python3.x 常用的新特性 print() 是函数,不是一个语句 raw_input()输入函数,改为 input() Python 3 对文本和二进制数据做了更为清晰的区分. 文本由unico ...

  7. Springboot热部署(热部署原理)和用IDEA开发需要的配置

    热部署原理 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>s ...

  8. SqlConnection 无法设置连接超时

    1.最有效的方法:对表格建立索引 2 在连接字符串中设置 Connection Timeout (默认15秒)3 设置 SqlCommand.CommandTimeout(默认是 30 秒)

  9. fgets、gets和scanf的区别

    gets()从stdin流中读取字符串,直至接受到换行符或EOF时停止,并将读取的结果存放在buffer指针所指向的字符数组中.换行符不作为读取串的内容,读取的换行符被转换为null值,并由此来结束字 ...

  10. go语言 robfig/cron包 实现定时 调用

    package main import ( "github.com/robfig/cron" "time" "fmt" "os&q ...