Three states of objects in hibernate and the difference between Saveorupdate method and merge method in the session class

Source: Internet
Author: User

First, a graph is used to illustrate an object, in Hibernate, the different states of an object after a different method is called


In Hibernate, the state of an object can be divided into three types as shown in the figure

Transient: Instantaneous object that does not have a corresponding record in the database, and that object is not associated with session

Persistent: Persistent object that has a corresponding record in the database, and the object is related to the session

Detached: Detach object that has a corresponding record in the database, and that object is not related to session

In three states, sessions are insensitive to changes except for persistent objects in two other states.


The Saveorupdate method and the merge method in the session class allow hibernate to determine whether an object is a newly added data record or to update an existing object in the database, the difference being

When the Saveorupdate method is invoked, the object becomes persistent from the instantaneous or detached state, and after the merge is invoked, the object remains detached.

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.