hibernatequery-cachefirst-level-cache

Hibernate First level Cache vs Query Cache


Is first level cache different from query cache in hibernate? I have seen articles mentioning about first level and query cache, so i am confused.


Solution

  • First level cache is enabled by default and is per session basis. Query cache is not enabled by default, is shared across multiple sessions and should always be used in conjunction with the second-level cache.

    To enable query cache, the following properties should be used:

    hibernate.cache.use_second_level_cache=true
    hibernate.cache.use_query_cache=org.hibernate.cache.EhCacheProvider
    hibernate.cache.use_query_cache=true