views:

93

answers:

2

What is second level cache in hibernate ?

+2  A: 

Perhaps this blog post can answer your question fully.

In general - first level cache is tied to sessions, second level isn't (so different sessions will hit the second level cache and not the DB).

Oded
+3  A: 

Hibernate comes with three different caches: first level, second level and query cache.

The first level cache is the Hibernate Session and is used to track the state of entities during the current Session (or unit of work). This is a transaction-level cache.

The second level cache shares entity state across various Session. This is a SessionFactory-level cache.

The query cache is used to cache queries (and their parameters) and their results.

Recommended readings

Pascal Thivent