"Go" Hibernate Object states

Source: Internet
Author: User

Hibernate is a persistence framework for object/relational mappings, and one of the main tasks it does is state management between objects and database table records. The object that operates in the Hibernate programming environment refers to the entity Pojo object, which exists in four states: Transient, persistent, detached, and removed. Here is an excerpt from the Web (from the Java Persistence with Hibernate book), which is a good illustration of the transition between these states.

This state change describes the relationship between a database and a mapped object, that is, a change in the state of a piece of data.

From this picture, we can see that

  • An object is transient (instantaneous) when it was created, meaning it has nothing to do with the database and exists only in memory
  • After the object has been saved or updated, it enters the persistent (persisted) state, where the object's corresponding record is already in the database, and the ID is generated
  • When the session's clear method is called, the object enters the detached state from persistent, and hibernate clears the object from the cache but still exists in the database
  • The detached state and persistent state can be converted to each other, and if the updated object is saved, the object enters the persistent state from the detached state
  • The object can also be fetched from the database via the load or get method, thus directly entering the persistent state
  • Finally, the object enters an irreversible removed state by invoking the Delete method of the session.

In fact, these state changes are more common sense, so just understand the basic principles, and then you can write code verification.

Source: http://ju.outofmemory.cn/entry/104975

"Go" Hibernate Object states

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.