Reputation: 12999
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:
setCacheable(true)
on queries I want to cacheI 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
Upvotes: 3
Views: 1647
Reputation: 23970
Though you do not mention it, you have also set hibernate.cache.use_second_level_cache=true|false
?
Upvotes: 1
Reputation: 570545
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!
Well, while it is possible to get statistics about cache hits from statistics (if you enable statistics by setting the property hibernate.generate_statistics=true
in 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.SQL
Log all SQL DML statements as they are executedorg.hibernate.cache
Log all second-level cache activityThis is IMO more useful than statistics to fine tune the behavior during development.
Upvotes: 2
Reputation: 8512
Hibernate does not gather statistics by default. Have you enabled statistics?
Upvotes: 0