Ula Krukar
Ula Krukar

Reputation: 12999

Hibernate: Query cache never used

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:

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

Upvotes: 3

Views: 1647

Answers (3)

extraneon
extraneon

Reputation: 23970

Though you do not mention it, you have also set hibernate.cache.use_second_level_cache=true|false?

Upvotes: 1

Pascal Thivent
Pascal Thivent

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 executed
  • org.hibernate.cache Log all second-level cache activity

This is IMO more useful than statistics to fine tune the behavior during development.

References

Upvotes: 2

Thierry Roy
Thierry Roy

Reputation: 8512

Hibernate does not gather statistics by default. Have you enabled statistics?

  • hibernate.generate_statistics = true

Upvotes: 0

Related Questions