Understanding of Hibernate's session cache

Source: Internet
Author: User

1. Four states of Java objects in hibernate

1) Temporary state: A Java object that has just been created by the new statement and is not persisted and is not in the session's cache, in a temporary state.

2) Persistent state: has been persisted and added to the session's cache. Java objects in a persisted state

3) Free State: has been persisted, but is no longer in the session cache.

4) Delete Status: Has been persisted, but is no longer in the session cache, such as: Session.delete (); Session.close ();

First Level cache: Session cache is built-in, cannot be uninstalled, and is also known as Hibernate's primary cache.

Second-level caching: Where the sessionfactory cache can be divided into two categories: built-in caches and external caches. Sessionfactory's built-in cache and session cache are similar in implementation, which is the data contained in some of the collection properties of the Sessionfactory object, which refers to the data contained in some of the session's collection properties. Sessionfactory's external cache is a configurable plug-in. By default, Sessionfactory does not enable this plugin. The external cached data is a copy of the database data, and the externally cached media can be either memory or hard disk. Sessionfactory's external cache is also known as Hibernate's second-level cache.

The difference between a first-level cache and a level two cache:

When hibernate accesses the data object according to the ID, it is first checked from the session level cache, and if a level two cache is configured, it is checked from the level two cache, the database is not found, and the results are placed in the cache by ID.


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.