I have a named query in my hibernate mapping file:
Code:
<query name="SelectDelegationWithDelegatorAndApp" cacheable="true">
<![CDATA[
from com.max.GoblPermissionDelegationHb p
where p.delegatee = :delegatee
AND p.effDate <= NOW()
AND p.expDate >= NOW()
AND p.goblApp = :goblApp
]]>
</query>
Note that cacheable is true, and I'm not providing a cache region so the query is cached in the default region. I want to get a list of all the queries that are currently cached in the default region, so I have the following code:
Code:
Map cacheEntries = sessionFactory.getStatistics().getSecondLevelCacheStatistics("org.hibernate.cache.StandardQueryCache").getEntries();
This code yields a ClassCastException on Line 50 of SecondLevelCacheStatistics.java because the key is of type QueryKey but it is being cast to a CacheKey.
Code:
public Map getEntries() {
Map map = new HashMap();
Iterator iter = cache.toMap().entrySet().iterator();
while ( iter.hasNext() ) {
Map.Entry me = (Map.Entry) iter.next();
map.put( ( (CacheKey) me.getKey() ).getKey(), me.getValue() ); // ClassCastException!
}
return map;
}
I had a similar issue before and Gavin told me my problem was that I was putting cached objects in the same region as cached queries. I've solved that problem, but now I'm doing something much simpler and I still have pretty much the same issue. If I'm not supposed to be accessing the standard query cache via the second level cache statistics api that's fine, but then I'd argue that "org.hibernate.cache.StandardQueryCache" shouldn't come back when I call sessionFactory.getAllSecondLevelCacheRegions().
Can anyone see what I'm doing wrong, or is there something amiss here?
Thanks,
Max
Hibernate version:
3.0.4
Mapping documents:
Code between sessionFactory.openSession() and session.close():
None, I'm doing this outside a session.
Full stack trace of any exception that occurs:
java.lang.ClassCastException: org.hibernate.cache.QueryKey
at org.hibernate.stat.SecondLevelCacheStatistics.getEntries(SecondLevelCacheStatistics.java:50)
Name and version of the database you are using:
MySql