Hibernate:a different object with the same identifier value was already associated with ...异常解决

今天在用框架更新时发现报a different object with the same identifier value was already associated wit此异常
原因:因为之前已经将该条记录取到了session缓存中,用update(游离态对象)方法时发生错误,一个游离态对象和一个持久态对象,具有相同OID,因此报错。

解决办法用merge(游离态对象),该方法应该是根据游离态对象的OID,执行select语句,将游离态对象转成了持久化对象,之后update()
但是我用的是别人的框架持久化层是不能随便修改的..尽量避免去修改内部的定义的接口..
想了想 是不是自己在action里查了一遍 然后Hibernate:session里就存在了游离对象,那么最后有拿这个对象更新的话就出错。
然后我用根据传入的对象ID 查出来赋给另一个对象然后 交替属性后 更新新的对象 竟然就可以了..(我也是这样解决的,更新对象之前,先根据ID查询)
原理不是很懂..但反正是解决了..忽忽

hibernate2.17中使用insertOrUpdate()方法  hibernate3.0以上使用merge()来合并两个session中的同一对象 
注:没有尝试,根据他的意思是保存更新的时候重新new一个对象试一下保存应该就可以了

a different object with the same identifier value was already associated with **(ssh异常转)的更多相关文章

  1. a different object with the same identifier value was already associated withthe session异常解决方案

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

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

  3. [转]解决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 ...

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

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

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

  6. a different object with the same identifier value was already associat

    问题:这个著名的托管态update更新异常 org.hibernate.NonUniqueObjectException: a different object with the same ident ...

  7. 解决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错误 这个错 ...

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

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

随机推荐

  1. CentOS开机自动运行程序的脚本

    有些时候我们需要在服务器里设置一个脚本,让他一开机就自己启动.方法如下: cd /etc/init.dvi youshell.sh   #将youshell.sh修改为你自己的脚本名编写自己的脚本后保 ...

  2. 纯js实现瀑布流布局及ajax动态新增数据

    本文用纯js代码手写一个瀑布流网页效果,初步实现一个基本的瀑布流布局,以及滚动到底部后模拟ajax数据加载新图片功能. 缺点: 1. 程序不是响应式,不能实时调整页面宽度: 2. 程序中当新增ajax ...

  3. 了解python

    Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.Python的文本文件是.py文件 Python的用途: 1.做日常事务,比如自动备份你的MP3 2.可以做网站,很多著名的网站包括 ...

  4. javascript 网络是否连接的几种方案

    js   网络是否连接的几种方案 1.通过html5的新属性: window.onload = function () {            var isOnLine = navigator.on ...

  5. T430 Windows 8 的USB3.0无法识别

    去年10月入的T430,开始操作系统用的Win7,USB3.0的移动硬盘可以识别.后来,等到T430的Win8驱动都出来一段时间后,安装了Win8.开始没发现USB3.0不能使用,后来用移动硬盘是才发 ...

  6. linux内核编程笔记【原创】

    以下为本人学习笔记,如有转载请注明出处,谢谢 DEFINE_MUTEX(buzzer_mutex); mutex_lock(&buzzer_mutex); mutex_unlock(& ...

  7. 索引 split2

    当往一个已经满了的索引块中插入新的索引条目时,将发生索引块的split,在9i下,分两种不同的情况进行split: (1)如果插入的索引键值不是最大的,将发生50-50的split,也就是说有bloc ...

  8. MyBaits的各种基本查询方式

    <?xml version="1.0" encoding="gbk"?> <!DOCTYPE mapper PUBLIC "-//m ...

  9. Eclipse 下如何引用另一个项目的资源文件

    为什么要这么做?可参考:Eclipse 下如何引用另一个项目的Java文件 下面直接说下步骤:(项目A 引用 项目B的资源文件) 1.右键 项目A,点击菜单 Properties 2.在弹出的框中,点 ...

  10. What is the difference between DAO and DAL?

    What is the difference between DAO and DAL? The Data Access Layer (DAL) is the layer of a system tha ...