The difference between the meaning of the "hibernate merge" Session1.merge (T entity) method and the Update method

Source: Internet
Author: User

1 "Session1.merge (T entity) Merge entity method.

2 The function of the merge is: A new object, if the object set an ID, then this object is treated as a Free State:

When the ID cannot be found in the database, the update will definitely report the exception, but with the merge, it will be insert.

When the ID can be found in the database, the update and merge performance is updated data, issued an UPDATE statement;

If the ID is not set, the object is treated as transient:

With the update, because there is no ID, so the exception will be reported, merge at this time will save the data, according to the ID production strategy to generate a piece of data;

3 "The function is similar to the Saveorupdate () method, the function is basically consistent, but slightly different."

the difference between the 4 and the Saveorupdate () method is:

1.saveOrUpdate () is a full update of the data

2.merge () method when updating data, such as the name of the data in the database This field is ' John Doe ', and the new data to be merged in the name field is NULL, the database name field data is not replaced, is still ' John Doe ', and the other fields are replaced.

The difference between the meaning of the "hibernate merge" Session1.merge (T entity) method and the Update method

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.