Hibernate divides the objects that are manipulated into three states:
1.
Instantaneous (Transient)/temporary state/Free State
Durable (persistent)
Off-tube (Detached)
Instantaneous object characteristics:
First, not in the session cache, it can be said that no one session instance association.
Second, there is no corresponding record in the database.
Persisting object Characteristics:
First, persistent objects are always associated with a session.
Second, the persisted object corresponds to the record in the database.
Thirdly, when the session cleans up the cache, it will update the database according to the change of persistent object.
Managed Object Characteristics:
First, session Disconnection Association
Second, hold OID
2. Differential analysis of three states:
As long as the session is associated with a persistent state.
The session is not associated, and no OID is a transient state.
Session is not associated with the OID is the Free State.
3. The conversion of persisted object states:
Conversion diagram:
Instantaneous object:
How to get---new out directly
Convert to persisted----save, Saveorupdate saving operation
Convert to Off-state----setId Set OID persistent identity (this ID is present in the database)
Persistent objects:
How to get----get, load, CreateQuery, Createcriteria by the session query method
Transition to transient state----Delete delete operation (data table does not have a corresponding record) (in fact, ID, but not OID)
Switch to off-state----close session, evict, clear remove object from session
Off-tube objects:
How to get directly-----cannot be obtained directly, it must be obtained by instantaneous object, persistent object conversion
Convert to transient----set the ID to null, or manually delete the corresponding data from the database
Transition to persistent----update, saveorupdate,lock (object re-placed in session, re-associated with session)
In hibernate all operations only recognize the OID, if the OID of two objects has been, it is directly considered to be the same object.
Three state resolution of objects in hibernate