开发者

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:

  • 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


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

  • Hibernate Core Reference Documentation
    • 3.4.6. Hibernate statistics
    • 3.5 Logging


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


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

  • hibernate.generate_statistics = true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜