解决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 ...
随机推荐
- Cocos暂停和重新开始游戏
创建按钮 cc.MenuItemFont.setFontSize(18); cc.MenuItemFont.setFontName("Arial"); var systemMenu ...
- 6.solr学习速成之multicore查询
查询关联多个core 再新建一个core 向每个core添加索引,修改 final static String SOLR_URL = "http://localhost:8080/solr/ ...
- spring mvc学习 总体概览
spring mvc 设计概览 springmvc处理http请求,主要是在web.xml中配置一个dispatcherservlet,然后由此进行拦截并处理请求返回相应,下面就针对源码大体记 ...
- Oracle 10g RAC 如何配置 VIP IPMP
metalink note 283107.1介绍了如何设置VIP的IPMP,此处记录一下设置过程. o Existing 10g RAC installation ^^^^^^^^^^^^^^^^^^ ...
- Hibernate4.3.5入门HelloWorld
本文给出一个简单的Hibernate4.3.5入门实例,配置方式采用XML文件方式(这种方式已经不是主流了,目前越来越多采用Annotation方式映射POJO实体) 代码结构如下图所示:主要用到hi ...
- linux进程的问题
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <pthread.h& ...
- Java微信公众平台开发(十一)--开发中微信公众平台/开放平台/商户平台的关联
转自:http://www.cuiyongzhi.com/post/55.html 微信公众平台(map.weixin.qq.com)/开放平台(open.weixin.qq.com)/商户平台(pa ...
- PYTHON 中的字符集
一.前言 Python中的字符编码是个老生常谈的话题,今天来梳理一下相关知识,希望给其他人些许帮助. Python2的 默认编码 是ASCII,不能识别中文字符,需要显式指定字符编码:Python3的 ...
- MySQL备份还原之三使用xtrabackup
1 xtrabackup安装 1)解压源码包 tar -xzvf percona-xtrabackup-2.1.7.tar.gz 2)安装perl环境(DBI/DBD) yum install per ...
- Mysql问题随记
[用户创建并授权远程访问] CREATE USER 'username'@'host' IDENTIFIED BY 'password’; @后面跟主机地址,即这个用户可以从哪些地址访问数据库,l ...