-->
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.  [ 4 posts ] 
Author Message
 Post subject: Issue with Query caching and empty result sets
PostPosted: Thu Jan 14, 2010 6:45 pm 
Newbie

Joined: Thu Jan 14, 2010 3:19 pm
Posts: 2
Hello. I am using hibernate-core-3.3.2GA with hibernate-jbosscache2-3.3.2GA and I have a question about the query cache.
When I run a query using a Criteria and after calling setCacheable(true), it works fine in the general case.
However, when I search for something that ends up with an empty result set, that query doesn't seem to be cached.
When I monitor the hibernate SQL log (or even monitoring the MySQL TCP connection) I see multiple identical queries performed and when I inspect the cache with jconsole, I don't see any lines corresponding to those queries with empty result sets.

Has anyone experienced this? Is it on purpose?
Thanks.


Top
 Profile  
 
 Post subject: Re: Issue with Query caching and empty result sets
PostPosted: Fri Jan 15, 2010 5:00 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Question: do you perform a NaturalKeyLookup query ?
In this case empty-result-sets are not stored into cache (and I can also explain you why)

StandardQueryCache#put()
...
if ( isNaturalKeyLookup && result.size() == 0 ) {
return false;
}
...


Top
 Profile  
 
 Post subject: Re: Issue with Query caching and empty result sets
PostPosted: Fri Jan 15, 2010 4:34 pm 
Newbie

Joined: Thu Jan 14, 2010 3:19 pm
Posts: 2
Thanks for the response.
I don't believe that a NaturalKeyLookup is being performed. The entity with which I was experiencing the issue doesn't have a natural key in its hibernate mapping. Is there any way that natural key lookups can happen automatically?
I re-tested the issue today and queries with empty result sets are being cached now (it only puts a timestamp in the value part).
It's really strange because this was something that was easily noticeable before and now it works fine without any known changes.


Top
 Profile  
 
 Post subject: Re: Issue with Query caching and empty result sets
PostPosted: Mon Jan 25, 2010 11:09 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
>>Is there any way that natural key lookups can happen automatically?

Hardly.
Namely I found todaya bug in the handling of natural key lookups
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4838
but there are 3 conditions which must be fullfilled to generate a natural key lookup:
1. use Restrictions.naturalId()
2. attributes in the where condition must be annotated as NaturalId
3. the NaturalId annotation must have the immutable property set to true.

>>... (it only puts a timestamp in the value part).
Yes, the timestamp is always saved as element nr. 0 in the result-set-array.

>>It's really strange because this was something that was easily noticeable before and now it works fine without any known changes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.