Keyword: hibernate update saveorupdate
Hibernate data update-session. Update/session. saveorupdate
Session. Update:
1. First, search for the key of the object to be updated in the internal cache of the current session. If it is found, the current object is considered to be in the persistent state and return. From this point, we can see that calling the update statement for an object in the persistent State does not play any role.
2. initialize the status information of the object (as the basis for dirty data check) and include it in the internal cache. Pay attention to the session here. the update method does not send an update SQL statement to update the data. execute (transaction. commit will call the session before the database transaction is actually committed. flush ).
Session. saveorupdate execution steps:
1. First, search in the internal cache of the session. If it is found, it will be returned directly.
2. Execute the Interceptor. isunsaved method corresponding to the object class (if any) to determine whether the object is not saved.
3. Determine whether the object is in the unsaved state based on unsaved-value.
4. If the object is not saved (transient state), call the Save method to save the object.
5. If the object is not saved (in the detached state), call the update method to re-associate the object with the session.
As you can see, the combined application of the SAVE and update Methods in saveorupdate is actually used. It does not add new features.