On the three states and transformation relationship of Java entity objects
In the latest hibernate document, four states are defined for hibernate objects (originally three states, and basically three states are asked during the interview), namely, new, or transient, managed, or persistent, detached, and removed, as shown in the following figure, In previous hibernate documents, the removed state is considered to be transient.
Transient: when an entity object is new, the object is in transient state, that is, the object is only a memory area for storing temporary data. If no variable references the object, it will be recycled by the garbage collection mechanism of the JVM. The data saved by this object has nothing to do with the database. Unless the transient object is associated with the database through the save(), saveorupdate(), persist(), merge() methods of session, and the data is inserted or updated into the database, this object will be converted into a persistent object. Persistent: instances of persistent objects have corresponding records in the database and have a persistent ID. After deleting a persistent object, the corresponding record in the database will be deleted. Then there is no corresponding relationship between the persistent object and the database record, and the persistent object becomes a removed state (which can be regarded as an instantaneous state). After the persistent object is modified, it will not be synchronized to the database immediately until the database transaction is committed. Free state: when the session is closed(), clear(), evict() or flush(), the entity object changes from persistent state to free state. Although the object has persistent and consistent identification values with the corresponding records in the database, it is in free state (also known as off pipe state) because the object has been cleared from the session and the object is not under persistence management. A free state object is very similar to a temporary state object, except that it also contains a persistent identity.
summary
The above is all about the three states and transformation relations of Java entity objects in this paper. I hope it will be helpful to you. Interested friends can continue to refer to this site: BlockingQueue of Java Concurrent learning to realize detailed explanation of producers and consumers, talk about the conversion between string array, string and shaping in Java, java to realize code sharing by traversing tree menu, etc. if you have any questions, you can leave a message at any time, and the editor will reply to you in time. Thank you for your support!