-->
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: Likely Bug: ClassCastEx. in SecondLevelCacheStatististics
PostPosted: Thu Nov 02, 2006 1:19 pm 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
Hibernate version:
My version is 3.0.5, but I just checked the SVN repository for the 3.2 trunk and the same problem exists, so presumably all versions.

Full stack trace of any exception that occurs:
The full stack trace would be entirely pointless in this case - here's the important stuff:

Code:
java.lang.ClassCastException: org.hibernate.cache.QueryKey
   at org.hibernate.stat.SecondLevelCacheStatistics.getEntries(SecondLevelCacheStatistics.java:50)
   at edu.taylor.domain.person.CachingPersonDirectory.logSecondLevelCacheContents(CachingPersonDirectory.java:22)
   at edu.taylor.domain.person.CachingPersonDirectory.getPersonWithBannerId(CachingPersonDirectory.java:30)
   at edu.taylor.domain.person.PersonLoadingFactoryBean.getObject(PersonLoadingFactoryBean.java:18)


Reproducing the problem
Enable the query cache for your SessionFactory, and then execute a Query something like this:

Code:
Query q = session.createQuery(
      "from " + PersonImpl.class.getName() + " p " +
      "where p.bannerId = ?");
q.setString(0, bannerId)
   .setCacheable(true)
   .setCacheRegion("getPerson");


Then try to grab the second-level cache entries for the query's region:
Code:
getSessionFactory()
   .getStatistics()
   .getSecondLevelCacheStatistics("getPerson")
   .getEntries();


And you get a stack trace. Nothing fancy going on here. The offending code:
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() );
      }
      return map;
   }


I suspect this was written before there *was* a query cache, when CacheKey was all you'd need to worry about. Such is no longer the case of course - queries use a different class as their key.

Would've posted straight to the JIRA since this issue appears so straight-forward, but as this would be my first submission, and as the entry page to the JIRA is awfully insistent that I'm probably just an idiot and everything is fine, here we are =) I can drum up a little test case that would reproduce the problem if necessary, but it doesn't seem like it would be in this case.

_________________
- Matt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 2:09 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please post to JIRA, thanks.


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.