First, a graph is used to illustrate an object, in Hibernate, the different states of an object after a different method is called
In Hibernate, the state of an object can be divided into three types as shown in the figure
Transient: Instantaneous object that does not have a corresponding record in the database, and that object is not associated with session
Persistent: Persistent object that has a corresponding record in the database, and the object is related to the session
Detached: Detach object that has a corresponding record in the database, and that object is not related to session
In three states, sessions are insensitive to changes except for persistent objects in two other states.
The Saveorupdate method and the merge method in the session class allow hibernate to determine whether an object is a newly added data record or to update an existing object in the database, the difference being
When the Saveorupdate method is invoked, the object becomes persistent from the instantaneous or detached state, and after the merge is invoked, the object remains detached.