Hibernate (vi) __ three states of objects

Source: Internet
Author: User

instantaneous (transient): There is no data in the database corresponding to it, more than the scope will be reclaimed by the JVM garbage collector, usually new and not associated with the session object.

Persistent (persistent): There is data in the database corresponding to it, currently associated with the session, and the associated session is not closed, the transaction is not submitted;

The persistent object state changes and the database is affected when the transaction commits (Hibernate detects it).

(When the object is save, the data is persisted, then Obj.set () commits the transaction and hibernate detects the modification of the data.

If the object is not persisted before the object is save (even in a transaction), hibernate cannot detect the data modification without affecting the database (Obj.set) ().

off-tube/free (detached): There is data in the database corresponding to it, but there is no session associated with it; the state of the off-tube object changes, hibernate cannot detect.

Hibernate Object three states, conversion diagram :

Commit() closes session

interview diagram : What happens if an object is judged ?

The main basis is : 1. See if the object is in session, 2, see if there are any corresponding records in the database.

Summarize:

transient State : no session Management , and no corresponding record in database

Persistent State : has session Management and is logged in the database

off -state/ Free State: There is no session Management, but there are records in the database .

Hibernate (vi) __ three states of objects

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.