Hibernation: Failed to sync database state with session

Possible duplicate:
Hibernate: another object with the same identifier value has already been associated with the session

When I try to insert a new record into a many-many multi-linked table, I get this error: Could not synchronize database state with session I can understand that this is something dealing with getSession () and session.close ()

But I can’t figure it out for sure. For each transaction, I create a new session. But I close all sessions when the user logs out. ie: create a hibernation session and bind it to an HttpSession. Then I destroy it when the user exits.

Several times after working on this problem, I get an error a different object with the same identifier value was already associated with the session:.

All these errors occur due to improper opening and closing of sessions.

Which method do you prefer to open and close. My project was building a web application. Everyone moves in the fact that the web application deals with the database.

Any suggestions!!!

+5
source share
1 answer

another object with the same identifier value was already associated with the session

Hibernate keeps track of the displayed objects that are running in the session so that it can detect any changes made to these objects and write them back to the database when the transaction is completed. If you were allowed to add different objects with the same database identifier object to the session, it would be ambiguous what state of the object should be recorded.

hibernate ( ). " ", , .

+10

All Articles