`
lliu26
  • 浏览: 25634 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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(),然后就可以了。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics