During performing some performance tuning in my application I have noticed, that hibernate query cache is never used.
I am quite sure I have it properly set up:
- hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
- hibernate.cache.use_query_cache=true
- I use
setCacheable(true)on queries I want to cache
I have set up a simple stress test, when I perform the same set of operations over and over by several threads. When I check hibernate statistics it turns out that query cache hitCount is zero!
What am I missing?
EDIT:
For all of you asking: I have set hibernate.generate_statistics = true
Well, while it is possible to get statistics about cache hits from statistics (if you enable statistics by setting the property
hibernate.generate_statistics=truein your configuration), this is IMO not the best way to diagnose caching “issues”.My suggestion would be to activate the logging of 1. the DML statements that are executed and of 2. the cache activity. The relevant logging categories are:
org.hibernate.SQLLog all SQL DML statements as they are executedorg.hibernate.cacheLog all second-level cache activityThis is IMO more useful than statistics to fine tune the behavior during development.
References