It took some time to understand the several States of Java objects in hibernate, so it is easy to understand. Record them here and share them with you !!
In hibernate, an object has three states: temporary state, persistent state, and free state.
These statuses are described as follows:
Temporary State: after a new object is created, the object is in the temporary state, that is, the object is only a memory area for saving temporary data. If no variable references this object, it will be reclaimed by the JRE garbage collection mechanism. The data domain database stored by this object has no relationship, unless the temporary object is associated with the database through session save or saveorupdate, and the data is inserted or updated to the database, this object is converted to a persistent object.
Persistent state: instances of persistent objects have corresponding records in the database and have a persistence ID. After the delete operation is performed on the Persistent object, the corresponding records in the database are deleted. Therefore, the persistence object does not have a correspondence with the database record, and the persistence object changes to a temporary state. After the persistence object is modified and changed, it will not be synchronized to the database immediately until the database transaction is committed. Before synchronization, the persistent object is dirty data.
Free State: after the session is closed, clear, or evict, the persistence object has the consistent value of the persistence identifier with the corresponding record of the database, but because the session has disappeared, the object is not in the persistent management, therefore, objects in the Free State (managed State) are very similar to objects in the temporary state, but they also contain persistent identifiers.
After finding some information, I think this figure can clearly explain the three states: