3 states of Hibernate entity class object life cycle

Source: Internet
Author: User

There are 3 types of Hibernate objects: Transient (Transient), persistent (persistent), and off-pipe (Detached). Objects that are in a persistent state are also known as PO (persistenceobject), Instantaneous and off-pipe objects are also called VO (Valueobject).

instantaneous State
A Java object that opens up memory space by the new command, for example. Student student=new Student ();

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.

Persistent State
An object in that state has a corresponding record in the database and has a persistent identity. If you use 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. Associate with the session instance;

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

off-pipe state
When the session associated with a persistent object is closed, the persisted object is turned into a riser object. When the de-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 will recycle it at the appropriate time;

2. More than the instantaneous object a database record identification value.


Address: http://blog.163.com/developers@yeah/blog/static/10780920520093260730883/

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.