Hibernate cache summary, hibernate Cache

Source: Internet
Author: User

Hibernate cache summary, hibernate Cache
Overview: it is used to improve the execution efficiency of hibernate ., There are two types: level-1 cache and level-2 Cache. level-1 cache is provided by hibernate and cannot be deleted. Level-2 Cache needs to be configured. Generally, it is replaced by redies instead of hibernate. 1. the primary cache is divided into two zones: the cache zone and the snapshot zone. the execution process 2.1 takes obtaining objects as an example when the user executes the session. get (user. class, 1L); The method first checks whether this object exists in the cache area. If yes, it gets the object from the cache area first and returns the object. If this object does not exist in the cache area, you can obtain this object from the database and place it in the cache area. In this case, the object is a persistent object. (The persistent State object has two flags: 1. If there is an OID, there is a primary key. 2. the second one is managed by the session, that is, placed in the first-level cache.) when the transaction commit method is executed, the system automatically determines whether the cache and snapshot areas are consistent, if they are inconsistent, the data will be synchronized in the cache. When updating the database, no update or addition operations will be performed because the database obtains the object. After the execution is completed, the transaction is committed. 2.2 Save the object method. Session. save (sysUser); the data is added to the database and the object is added to the cache area at the same time. In this case, the object is a persistent object. (The persistent State object has two flags: 1. If there is an OID, there is a primary key. 2. The second one is managed by the session, that is, placed in the first-level cache. Update when the transaction is committed. This is the same as obtaining objects. . When the persistent State object is modified. When this method (User user = Session. get (user. classs, 1l);), it will get the persistent State object, this object is also in the cache and snapshot area of the first-level cache. Execute this method: (user. setName ("Zhang San");), the object is changed, and the cache area in the first-level cache is also changed. When the transaction commit method is executed, when the transaction commit method is executed, the system automatically determines whether the cache and snapshot areas are consistent. If they are inconsistent, the system synchronizes data in the cache. Update the database. After the data is updated, the data in the cache and snapshot areas is consistent. The transaction will also be committed.

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.