I'm in the process of setting up query caching for a web application, and I'm noticing that all of my HQL queries that include @Inheritance annotated Entities (and subclasses) never result in a cache hit. However, HQL queries that reference normal entities do result in cache hits.
Looking at the debug statements, EhCache uses the same sql key for each query against the StandardQueryCache region. So, in theory, they should be hitting. In fact, the EhCache MemoryStore spits out a message indicating a hit.
Code:
DEBUG net.sf.ehcache.store.MemoryStore - org.hibernate.cache.StandardQueryCacheCache: org.hibernate.cache.StandardQueryCacheMemoryStore hit for sql: select blah blah blah...
Unfortunately, the Hibernate statistics indicate otherwise. For a simple HQL query
"FROM InheritanceBean o" that's executed 5 times, I get the following stats:
Code:
QueryCachePutCount = 5
QueryCacheHitCount = 0
QueryCacheMissCount = 5
But for
"FROM NormalBean o" that's executed 5 times, I get the following stats:
Code:
QueryCachePutCount = 1
QueryCacheHitCount = 4
QueryCacheMissCount = 1
Has anyone seen this behavior before or, better yet, can explain why this is happening and how to get around it? Has anyone tried to set up query caching on inheritance mapped Entities before? Any help would be greatly appreciated. Thanks!
Steve
- Using Hibernate 3.5.2, EhCache 1.5.0 (with no custom ehcache.xml settings), Spring Framework 3.0.1.RELEASE-A (HibernateTemplate with setCacheQueries set to true) with single table inheritance.