Hibernate Query Cache

In Hibernate, we can cache frequently used query results using Query cache. To enable Query cache, enable the “use_query_cache” property in hibernate.cfg.xml file : <property name="hibernate.cache.use_query_cache">true</property> To use Query cache, we also need to set the cacheable property on the Query to true by invoking the Query.setCacheable() method. Hibernate Query Cache Example In the following […]

Hibernate Caching : Second Level Cache

Second Level Cache or L2 Cache The Second Level Cache in Hibernate is optional and is external to Hibernate. This cache is globally available via the SessionFactory class to the entire application. Hibernate comes with built-in support for caching libraries Ehcache and Infispan. However, any Cache provider can implement the org.hibernate.cache.spi.CacheProvider interface provided and provide […]

Hibernate Caching : First Level Cache

Hibernate provides multilevel caching framework : First Level Cache (Also called L1 cache or Session cache) Second Level Cache (L2 Cache) Query Cache   First Level Cache / L1 Cache / Session Cache The First level cache(L1 cache) is the Session cache through which all the db requests must pass. The L1 cache ensures that […]