Hibernate support two type of cache one is first level cache and other is second level cache.
First level cache is a session level cache and it is always associated with session level object. This type of cache is used for minimizing Db interaction by caching the state of the object. That is instead of updating after every modification done in the transaction, it updates the transaction only at the end of the transaction.
Second level cache is session factory level cache and it is available across all sessions.While running the transactions, in between it loads the objects at the Session Factory level, so that those objects will be available to the entire application, not bound to a single user. By default, it is disabled in hibernate.
|Sr. No.||Key||First level cache||Second level cache|
First level cache is a session level cache and it is always associated with session level object
Second level cache is session factory level cache and it is available across all sessions
It is enabled by default.
It is not enabled by default.
It is available for a session
It is available across all session.
No Extra configuration required
We have to decide which concurrency strategy to use and also need to configure cache expiration and physical cache attributes.