Java objects in hibernate have several States, and their relationships (differences and Mutual Conversions)

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.