3 states of objects in Hibernate: Transient state, persistent state, and off-tube state

Source: Internet
Author: User

There are 3 types of Hibernate objects: Transient (Transient), persistent (persistent), and off-state (Detached). Objects that are in persistent state are also known as PO (Persistence object), and instantaneous and de-tube objects are also known as VO (Value object).
1. Instantaneous state
A Java object that opens up memory space by the new command,

For example: Thinksoar Thinksoar = new Thinksoar ("name", "Brother side");

If the object is not referenced by a variable, it will be reclaimed by the Java virtual machine.

Instantaneous objects exist in memory, it is the carrier that carries the information, does not have any relation with the database data, in Hibernate, the instantaneous object can be associated with the database through the session's save () or Saveorupdate () method, and the data corresponding to the inserted database , the instantaneous object is transformed into a persisted object.

2. Persistent state
The object in that state has a corresponding record in the database and has a persistent identity. In the case of Hibernate's Delete () method, the corresponding persistent object becomes instantaneous, because the corresponding data in the database has been deleted, and the object is no longer associated with the database's record.

When a session executes close () or clear (), evict (), the persisted object becomes a de-tube object, at which point the persisted object becomes a de-tube object, while the object has a database recognition value, but it is not under the management of Hibernate persistence layer.

Persistent objects have the following characteristics:

1;. Associated with the session instance;

2;. There is a record associated with it in the database.

3. Off-Pipe State

When the session associated with a persisted object is closed, the persisted object is turned into a de-tube object. When the off-tube object is re-associated to the session, it is again transformed into a persistent object.

The de-tube object has the recognition value of the database and can be transformed into a persistent object by means of update (), Saveorupdate () and so on.

The off-pipe object has the following characteristics:

1;. Essentially the same as an instantaneous object, when no variable references it, the JVM reclaims it at the appropriate time;

2;. A database record identification value is more than an instantaneous object.

3 states of objects in Hibernate: Transient state, persistent state, and off-tube state

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.