Three state resolution of objects in hibernate

Source: Internet
Author: User

Hibernate divides the objects that are manipulated into three states:

1.

Instantaneous (Transient)/temporary state/Free State

Durable (persistent)

Off-tube (Detached)

Instantaneous object characteristics:

First, not in the session cache, it can be said that no one session instance association.

Second, there is no corresponding record in the database.

Persisting object Characteristics:

First, persistent objects are always associated with a session.

Second, the persisted object corresponds to the record in the database.

Thirdly, when the session cleans up the cache, it will update the database according to the change of persistent object.

Managed Object Characteristics:

First, session Disconnection Association

Second, hold OID

2. Differential analysis of three states:

As long as the session is associated with a persistent state.

The session is not associated, and no OID is a transient state.

Session is not associated with the OID is the Free State.

3. The conversion of persisted object states:

Conversion diagram:

Instantaneous object:

How to get---new out directly

Convert to persisted----save, Saveorupdate saving operation

Convert to Off-state----setId Set OID persistent identity (this ID is present in the database)

Persistent objects:

How to get----get, load, CreateQuery, Createcriteria by the session query method

Transition to transient state----Delete delete operation (data table does not have a corresponding record) (in fact, ID, but not OID)

Switch to off-state----close session, evict, clear remove object from session

Off-tube objects:

How to get directly-----cannot be obtained directly, it must be obtained by instantaneous object, persistent object conversion

Convert to transient----set the ID to null, or manually delete the corresponding data from the database

Transition to persistent----update, saveorupdate,lock (object re-placed in session, re-associated with session)

In hibernate all operations only recognize the OID, if the OID of two objects has been, it is directly considered to be the same object.

Three state resolution of objects in hibernate

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.