
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between First Level Cache and Second Level Cache in Hibernate
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 |
---|---|---|---|
1 |
Basic |
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 |
2 |
Enabled |
It is enabled by default. |
It is not enabled by default. |
3 |
Availability |
It is available for a session |
It is available across all session. |
4 |
Configuration |
No Extra configuration required |
We have to decide which concurrency strategy to use and also need to configure cache expiration and physical cache attributes. |