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.