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. linux 安装scons

     scons是一个Python写的自动化构建工具,需要安装python和scons后才能运行,能够跨平台.其集成功能类似于autoconf/automake ,是一个简洁可靠的工具.现在很多系统都自带 ...

  2. html中offsetTop、clientTop、scrollTop、offsetTop各属性

    HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对 ...

  3. Spring AOP术语

    1.AOP术语     1)连接点(Joinpoint)     程序执行的某个特定位置:如类开始初始化前.类初始化后.类某个方法调用前.调用后.方法抛出异常后.一个类或一段程序代码拥有一些具有边界性 ...

  4. iphone 6 设置自定义铃声(未越狱)

    环境: ipone 6 iTunes 12.4.0.119 IOS 9.3.2 先把需要设置的铃声下载到电脑上,然后打开iTunes下的文件->将文件添加到资料库,如图: 2.在音乐列表里右击所 ...

  5. Babel 6 配置

    Babel 6 较之前版本有些变化,几个比较重要的点. npm package babel 已经不在使用了,分成了下列几个 package babel-cli, 适用于命令行 babel-core, ...

  6. 解决docker中DNS查询的问题

    I got a dns error that i can not access dns server, that caused by : /etc/resolv.conf you can find t ...

  7. php面试题整理

    PHP经典面试题:(不断跟进补充中...) 1.用PHP打印出前一天的时间格式是2009-02-10 22:21:21(2分) echo date('Y-m-d H:i:s', strtotime(' ...

  8. Hadoop集群(第9期)_MapReduce初级案例

    1.数据去重  "数据去重"主要是为了掌握和利用并行化思想来对数据进行有意义的筛选.统计大数据集上的数据种类个数.从网站日志中计算访问地等这些看似庞杂的任务都会涉及数据去重.下面就 ...

  9. ogre世界坐标鱼屏幕坐标相互转换

    bool worldCoordToScreen(Vector3 objPos, Camera* cam, Vector2 screenRect,  Vector2& screenPos) { ...

  10. word-pattern(mock)

    注意: // String要用equals,不然比较结果不对,会出bug// 使用String.split // boolean打印用 %b  // abba 对应 cccc 也不行, 所以要用set ...