Hibernate快速入门[转载]
|
软件开发团队的常用软件
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session 意思就是说你在现有的Session中已经绑定了一个对象,而这时,你还要强行将已经持久化的对象再重新加入到Session中。在同一个session 当中只能存在一条相同对象或者叫po,当你试图把它再次load近来,并打算对他进行update时就会报这一个错误。还有者当你用 session.lock()时,也可能报这一个错误。总而言之,是在你的Session中已经存在了多个你想要更新的对象了。
下面是Hibernate FAQ上的解释:
I called saveOrUpdate() or update() and got a NonUniqueObjectException!
The session maintains a unique mapping between persistent identity and object instance, in order to help you avoid data aliasing problems. You cannot simultaneously attach two objects with the same class and identifier to the same session.
The best way to avoid any possibility of this exception is to always call saveOrUpdate() at the beginning of the transaction, when the session is empty.
In Hibernate3, you can try using the merge() operation, which does not reattach the passed instance.
分类: | (共有0条评论)



