What is the difference between Hibernate's Saveorupdate (), Save (), and update ()?

Source: Internet
Author: User

Saveorupdate () If the incoming object has an update operation in the database, do the save operation if it is not.
Save () generates a record in the database and, if there is one in the database, an error message that there is a duplicate record.
Update () is updating records in the database

The primary key plays a key role in the Saveorupdate () method, only if the value of the primary key is not empty, insert or update is determined, otherwise the direct insert

If the primary key is not empty, the saveorupdate () operation can be performed.

Saveorupdate is when you use a Pojo object in an indeterminate situation, in order to change its state to the present state when the object is present, and to persist it if it does not exist, that is to say, whatever it is, to have this object.

Save is the primary key that returns the inserted data, and saveorupdate is void
The Save method is more suitable for determining the primary key that is to be inserted and to get the inserted data
And Saveorupdate is more inclined to be unsure whether to insert or update, and you don't need to get his primary key


On the other hand, if you are unsure whether the object you want to insert or update is not persistent or free State. If you save a persistent state or update a Free State, this is problematic, and you need to use Saveorupdate
Overall, if you can determine the state of the object you are about to manipulate, you do not need to use saveorupdate

What is the difference between Hibernate's Saveorupdate (), Save (), and update ()?

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.