Java Hibernate objects
Thanks to the recent learning of Java Hibernate, there are several states of Java Hibernate Objects sorted, and interested friends can look at it.
instantaneous (transient): There is no data in the database that corresponds, and more than the scope is reclaimed by the JVM garbage collector, which is generally new and has no association with the session.
Persistent (persistent): data in the database corresponding to the current session with the association, and the associated session is not closed, the transaction has not been submitted;
Persistent object state changes that affect the database when a transaction commits (Hibernate can detect).
(When the object is save, the data is persisted, then Obj.set () and then commits the transaction hibernate detects the modification of the data.
And if before the Save this object (even in the transaction), that is to have not persisted this object, uses Obj.set () then hibernate cannot detect the data modification, does not affect the database)
Tube/Free (detached): There is data in the database corresponding to it, but currently there is no session associated with it, the removal of the object state changes, hibernate can not detect.
Hibernate three states of the object, conversion diagram:
Commit () Closes session
Interview Chart: If you judge an object in what state?
The main basis is: 1. See if the object is in session, 2, see if there is a corresponding record in the database
Summarize:
Instantaneous state: No session management, while database does not have corresponding records
Persistent state: There is session management, while there are records in the database
Off-tube/Free State: No session management, but there are records in the database.
Thank you for reading, I hope to help you, thank you for your support for this site!