Search code examples
hibernateobject-persistence

Second level Cache in hibernate disabled by default


The session factory Cache needs to be explicitly configured in hibernate to fine tune the query performances.

Is there a relevant reason that can be agreed upon, why first level Cache(session specific) is enabled out of the box in hibernate while the second level Cache (session factory specific) is not ?


Solution

  • It is as per the JPA specifications... Implementation of L2 cache is optional for the JPA providers.. Hibernate and Eclipse Link however implement it, but you need to manually configure that...

    Here you can find everything about cache docs.oracle.com/javaee/6/tutorial/doc/gkjio.html

    NOTE: One consequence of using a second-level cache in an application is that the underlying data may have changed in the database tables, while the value in the cache has not, a circumstance called a stale read.