Home  >  Article  >  Java  >  Understanding the first-level cache and snapshot area in Hibernate

Understanding the first-level cache and snapshot area in Hibernate

巴扎黑
巴扎黑Original
2017-06-26 11:25:552255browse

At first I thought this snapshot area was difficult to understand. After reading a lot of blogs online, I started to understand. I understand it based on ADO.NET. There is a class in ADO.NET called SqlCommandBuilder. In my opinion, it is the thing corresponding to the Hibernate snapshot area in ADO.NET. This SqlCommandBuilder can build SQL statement, and when the Update method is called, the information in the database can be updated (including update and delete). One of the essential enumeration classes is the row status bit RowState class. I combine this row status bit with Hibernate The comparison (compare cache area and snapshot area) is regarded as corresponding. However, when refreshing the cache area, Hibernate does a comparison of the contents of the cache area and the snapshot area (

If it is found to be different, it updates the snapshot area and stores an update SQL statement. If it is not a refresh operation, , but commits the transaction operation, then not only will the updata statement be stored, but also the SQL

will be sent to the database to execute the update. However, ADO.NET did not compare, but recorded (that is, changed the row RowStae value), and finally SqlCommandBuilder updates to the database based on this status bit and primary key. In fact, from a certain perspective, comparison is also a kind of recording (similar to modifying the row status bit). Until the transaction is committed, it is updated to the database. .

Add a sentence, I understand snapshot as a snapshot of the database (initially a snapshot of certain rows of the database, and then after a single operation, it is no longer a snapshot of the database) A snapshot is taken, but after the transaction is committed, it becomes a snapshot of part of the database rows.)

For more information about SqlCommandBuilder, please read this blog

[

SQLCommandBuilder Class##There is also this class

RowSate classMaybe I didn’t explain it clearly enough, but this is my current understanding.

The above is the detailed content of Understanding the first-level cache and snapshot area in Hibernate. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn