a different object with the same identifier value was already associated with the session解决方案
org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identifier value was already associated with the session: [cn.ac.iscas.core.entity.pm.cm.CmPlanBaseline#]; nested exception is org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [cn.ac.iscas.core.entity.pm.cm.CmPlanBaseline#]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:)
at cn.ac.intec.entity.orm.impl.SessionImpl.saveOrUpdate(SessionImpl.java:)
at cn.ac.intec.entity.orm.impl.SessionImpl.insertOrUpdate(SessionImpl.java:)
at cn.ac.intec.entity.orm.impl.SessionImpl$$FastClassByCGLIB$$550f49cd.invoke(<generated>)
触发场景,解决方案:
1. show业务操作,开启一个session ,从中查出一些实体,这时某个实体是存在于session中的持久化对象。通过业务逻辑将此实体用于页面展示。此时这个session并未关闭。
2. 这时执行一步save业务逻辑,将上一步获得的实体id传回后台 。这时通过new的方式创建了一个临时对象,并且我将传回的id作为主键赋值给了临时对象。然后调用了session.save(obj); 方法 。。。抛出异常。
原因很简单,session中有2个oid一样的对象,hibernate不知道该让哪个持久化到库里。当时解决思路也很清晰,直接clear();清空一下 session缓存不就Ok了。但是clear打击面太广了(慎用!)。其他一些“无辜”对象也被杀掉,导致其他业务无法进行了。
后来在session中发现一个evict方法,“定点清除”对象缓存。这下就好了,先用传回来的id用get方法(其实这里用load方法也行反正都是从缓存中加载)获得session里的持久化实体,然后杀掉,再保存临时实体。没问题了。
a different object with the same identifier value was already associated with the session解决方案的更多相关文章
- a different object with the same identifier value was already associated with the session:
hibernate操作: 实例化两个model类,更新时会提示 a different object with the same identifier value was already assoc ...
- [转]解决a different object with the same identifier value was already associated with the session错误
1.a different object with the same identifier value was already associated with the session. 错误原因:在h ...
- a different object with the same identifier value was already associated with the session:错误;
当出现a different object with the same identifier value was already associated with thesession时,一般是因为在h ...
- 解决a different object with the same identifier value was already associated with the session错误
[转]解决a different object with the same identifier value was already associated with the session错误 这个错 ...
- hibernate中一种导致a different object with the same identifier value was already associated with the session错误方式及解决方法
先将自己出现错误的全部代码都贴出来: hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> ...
- Hibernate Error: a different object with the same identifier value was already associated with the session
在执行Hibernate的Update操作时,报错:a different object with the same identifier value was already associated w ...
- 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 ...
- 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 ...
随机推荐
- win8.1下安装双系统ubuntu14.04.3
一.去ubuntu官网下载长期支持版的系统,64位还是32位由物理内存而定,4G以下用32位,4G以上(包括4G)使用64位. 二.若64位的系统,下载下来的文件名应该是ubuntukylin-14. ...
- MAC OS、Windows 、HTML,CSS,font-family:中文字体的英文名称
宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 PMingLiU 细明体 Ming ...
- python之wheel 包命名规则、abi 兼容和安装
一.windows安装python包,遇见的问题 1.python3以后的版本,安装python包,可以直接使用pip安装,但是安装时偶尔报错 2.安装python源码包,如何确定自己该安装哪个版本, ...
- python字符串常用
参考这一篇: http://www.runoob.com/python/python-strings.html
- 【常见Web应用安全问题】---4、Directory traversal
Web应用程序的安全性问题依其存在的形势划分,种类繁多,这里不准备介绍所有的,只介绍常见的一些. 常见Web应用安全问题安全性问题的列表: 1.跨站脚本攻击(CSS or XSS, Cross Si ...
- 如何在 Linux 上使用 x2go 设置远程桌面
https://linux.cn/article-5708-1.html 由于一切都迁移到了云上,作为提高职员生产力的一种方式,虚拟远程桌面在工业中越来越流行.尤其对于那些需要在多个地方和设备之间不停 ...
- volatile浅析
volatile的意思是不稳定的.易变的,但在多线程中却跟字面意思一毛钱关系没有.作为一个变量修饰符,它主要有两个作用:一个是告诉大家,该变量是一个在多个线程之间均可见的变量:另一个是告诉java虚拟 ...
- if的用法
if用法举例:求分数的等级 # include <stdio.h> int main(void) { float score; //score分数 printf("请输入您的考试 ...
- Unit05: JavaScript对象概述 、 常用内置对象一 、 常用内置对象二 、 常用内置对象三
Unit05: JavaScript对象概述 . 常用内置对象一 . 常用内置对象二 . 常用内置对象三 常用内置对象使用演示: <!DOCTYPE html> <html> ...
- 2DAY初识python
一.变量 1 什么是变量之声明变量 #变量名=变量值 age=18 gender1='male' gender2='female' 2 为什么要有变量 变量作用:“变”=>变化,“量”=> ...