Hibernate Error: org.hibernate.NonUniqueObjectException

Hibernate 删除指定行的时候出现:
Hibernate Error: org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

在stactoverflow上面看到相关解答:
Your problem is that the object you previously loaded still exists in you hibernate session. I see two ways to cope with that.

1.) tell the hibernate session to merge your modified object with the one in the session

session.merge(object)
2.) kick the old object out of the session before writing the updated object to the session. session.clear() might work.

意思是说之前load的object在hibernate session中还存在。
在删除操作之前,加上session.clear(),然后就可以了。

你可能感兴趣的:(Hibernate,Associated)