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.