Hibernate: Could not synchronize database state with session [duplicate]

瘦欲@ 提交于 2019-12-05 07:47:14

a different object with the same identifier value was already associated with the session

Hibernate keeps track of the mapped objects worked on within a session so it can detect any changes made to these objects and write them back to the database when the transaction is committed. If you were allowed to add different objects with the same database identifier object to a session, it would be ambiguous which object's state should be written.

Working with objects from the hibernate reference manual explains this (and ways to resolve it) in detail. Of particular interest is the section titled "Modifying detached objects", but will need want to read the introduction too to understand the terms used.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!