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. DB2时间操作

    以下内容选编自<DB2 基础: 日期和时间的使用> 1.使用SQL获取数据库服务器当前时间戳 SELECT current date FROM sysibm.sysdummy1 SELEC ...

  2. http://blog.csdn.net/xiamizy/article/details/40781939

    http://blog.csdn.net/xiamizy/article/details/40781939

  3. 爬虫Larbin解析(二)——sequencer()

    分析的函数: void sequencer() //位置:larbin-2.6.3/src/fetch/sequencer.ccvoid sequencer() { bool testPriority ...

  4. 第一个Struts2程序

    Struts2.3.16, Tomcat6.0.37,Java8 /web.xml <?xml version="1.0" encoding="UTF-8" ...

  5. zf2 安装

    下载实例程序 ZendSkeletonApplication 解压至D:\xampp\htdocs并重命名为ZendSkeletonApplication 下载Zend Framework 2.0最新 ...

  6. 基于EntityFramework的权限的配置和验证

    1.   概要 本文主要介绍公司现有系统框架的权限体系,和一些待扩展功能的说明.目前该权限体系基于角色构建(RBAC),原则上,系统中不允许出现对用户.组织等其他对象指派权限的情况. 2.   权限分 ...

  7. Android控件系列之CheckBox

    学习目的: 1.掌握在Android中如何建立CheckBox 2.掌握CheckBox的常用属性 3.掌握CheckBox选中状态变换的事件(监听器) CheckBox简介: CheckBox和Bu ...

  8. Zend13.0 +XAMPP3.2.2 调试配置

    Zend 调试PHP有3种方式: (1)PHP CLI APPLICATION (2)PHP Web Application (3)PHP UnitTest (1).(2)两种方式配置相似,下图是配置 ...

  9. JavaScript —— 局部变量和全局变量

    JS的全局变量有3种声明方式: 1.Function 外 var v_myVar; 2.Function 内 v_myVar; 3.window.v_myVar window.v_myVar 全局变量 ...

  10. 《c程序设计语言》读书笔记--大于8 的字符串输出

    #include <stdio.h> #define MAXLINE 100 #define MAX 8 int getline(char line[],int maxline); voi ...