-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: StandardQueryCache issue
PostPosted: Mon May 30, 2005 4:01 pm 
Newbie

Joined: Wed Apr 27, 2005 10:22 pm
Posts: 8
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 21, 2005 7:32 pm 
Beginner
Beginner

Joined: Sat Jan 22, 2005 9:11 am
Posts: 35
Location: London
I agree. At the moment (v 3.0.5), you cannot use the Statistics Api to display query cache entries.

The issue is very simple to reproduce in any hibernate app:

- run a cacheable query so the cache region has an entry
- get the SecondLevelCacheStatistics for this region
- call getEntries
- bang! ClassCastException

It's not the end of the world (I can go direct into my cache provider to get this info) but it would be nice if this worked. On a quick browse of the source, maybe could be fixed by having QueryKey and CacheKey implement a common interface with a getKey method.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.