Java Hibernate objects (instantaneous state, persistent state, de-pipe state) detailed _java

Source: Internet
Author: User

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!

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.