Hibernate batch update data

Source: Internet
Author: User

Today, I encountered a problem in a project, which is described as follows:

Batch operations must be performed on a batch of data that meets the conditions. If the conditions are met, batch updates are performed. If the conditions are not met, data is not submitted. However, data is updated every time the conditions are not met, query relevant information and discover. When hibernate closes the session, it will check the persistent objects in the memory. That is to say, if the persistent objects in the memory are inconsistent with the objects in the data volume, hibernate will update the object whether or not you update the object.

The solution is as follows:

1. perform in-depth cloning of the PO category of this batch of data (I have not verified it, it is feasible on the Internet)

2. Call getSession () every time a piece of data is queried (). evict (obj); changes the status from persistent state to free state. If hibernate is explicitly called when it is disabled, the status is updated; otherwise, no database updates will be performed.

Summary: although this example is very simple, it is a typical example for understanding the working principle of hibernate. It can be easily recorded for future reference.

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.