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. 【解惑】让人头疼的"相等"关系

    Java中判断相等关系一般有两种手段:(1) “==”关系操作符  (2) equals()方法. 显然,基本数据类型变量之间只能用"==".而对象之间两种手段都是合法的.但是有很 ...

  2. Android百度地图开发05之公交信息检索 + 路线规划

    在上一篇blog中介绍过POI检索的使用,本篇blog主要介绍公交信息检索和线路规划的内容. 公交信息检索 实际上,公交信息检索与POI检索.在线建议检索非常相似,也是把你需要检索的信息发送给百度地图 ...

  3. 下载的时候如果文件名是中文就变成zip.zip

    struts2 /WEB-INF/web.xml <?xml version="1.0" encoding="UTF-8"?> <web-ap ...

  4. jquerymobile UI使用

    <!DOCTYPE HTML> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  5. javascript 高效按字节截取字符串

    做为一个前端开发人员在网页展示中经常会碰到,标题过长,需要截取字符串,用CSS的实现的话各种兼容问题,各种坑. 让后台程序截一下,又各种推托,让后台按字节截一下更是和要了后台老命一样,最后可能只会安字 ...

  6. Ext的正则表达式

    http://www.cnblogs.com/azai/archive/2010/12/31/1923140.html   今天看到一篇关于Extjs正则表达式比较系统的总结. 使用extJs时能常用 ...

  7. django-based blog- mezzanine

    django-based blog- mezzanine zinnia 博客 hydra  暴力破解

  8. 如何在ubuntu下安装合适的翻译词典

    http://jingyan.baidu.com/article/9faa7231523dd6473c28cb3f.html

  9. leetcode Database3

    一.Rank Scores Write a SQL query to rank scores. If there is a tie between two scores, both should ha ...

  10. Selenium系列教程(2)

    Selenium RC(Selenium远程控制) Selenium RC是一个用Java编写的,允许用户使用无论哪种编程语言对基于Web的应用程序构建测试脚本的工具.Selenium RC克服了Se ...