NonUniqueObjectException: a different object with the same identifier va lue was already associated
来源:互联网 发布:淘宝证件相片拍摄 编辑:程序博客网 时间:2024/06/10 20:35
今天遇到了这个问题:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:……
找其原因是因为同一个object,如一个person在seession里保存了一份,而增加的别的object,如company的时候,由于做了关联关系,从数据库里又get了一个person,而这个person和seession里的person是同一个,把get出来的person set 到了company里,像这样,compnay.setPerson(person).在增加company的时候就出现了这个错误。
网上查了一下,在增加object时,先做一个这样的操作,说是把相同的object合并一下:
object = session.merge(object);
然后再保存
session.save(object);
我试了试,确实可以解决。
但因为我的操作中,在增加之后还有一个修改的操作,增加时是成功了,但在修改的时候就又出新的错了,所以我最后的解决办法是:
用程序来判断,在拿person的时候,session里有就从session里拿,没有再get出来,最后再保存company,就没问题了。
0 0
- NonUniqueObjectException: a different object with the same identifier va lue was already associated
- org.hibernate.NonUniqueObjectException:a different object with the same identifier value was already associated with the sessio
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the sessio
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the sessio
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the sessio
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the sessio
- org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the sessio
- 解决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错误
- 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错误
- 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
- 解决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
- 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
- a different object with the same identifier value was already associated with the session
- ATM系统
- 循序渐进学设计模式(一)
- Android反编译操作详解
- 领军杰出青年高燃二次创业
- 我
- NonUniqueObjectException: a different object with the same identifier va lue was already associated
- 操作系统面试题(三)
- HDU-1176 免费馅饼
- ioremap
- GridView 动态绑定列
- 跟我一起学Makefile
- ASIHTTPRequest系列(四):Cookies
- Javascript:继承和原型链
- 杜拉斯和她的情人