-->
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: Caching scalar queries
PostPosted: Fri Apr 29, 2005 6:43 am 
Newbie

Joined: Fri Apr 29, 2005 6:27 am
Posts: 2
Hi,

I have create a cacheable query like this :

Code:
session.createQuery(
        "select count(*) from mt.domain.geo.Land land
                   where land.landCode=:landCode")
                                .setString("landCode", code)
                                .setCacheable(true)
                                .iterate().next();

the problem is that the query result does not seem to get cached.

the caching works for other cached queries returning mapped object - so no prob with the configuration, I think:-)

hibernate.cache.use_query_cache is set to 'true'
and I have <cache usage="read-only"/> in the mt.domain.geo.Land mapping.

I know it is not being cached because hibernate.show_sql is set to 'true' and I see a
Code:
select count(*) as x0_0_ from land land0_ where (land0_.co_land=? )
each time the app is calling that query.

any idea ?

thanks,

Fred


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 6:56 am 
Newbie

Joined: Fri Apr 29, 2005 6:27 am
Posts: 2
Ok,

found it !

I changed it to
Code:
session
        .createQuery(
                "select count(*) from mt.domain.geo.Land land where land.landCode=:landCode")
        .setString("landCode", code)
        .setCacheable(true)
        .list().get(0);

and now it's ok...

see ya,

Fred


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 3:32 pm 
Regular
Regular

Joined: Thu May 26, 2005 12:20 am
Posts: 72
thank you very much for posting a solution to your problem after you found it. I was having the same question and that solution fixed it for me as well.


=)

Dan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 5:56 pm 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
Thanks for reporting your findings.

In org.hibernate.hql.QueryTranslatorImpl, the code for list() does try to go through the query cache but that for iterate() always executes the query.

I would expect the iterate method to also try the query cache before executing the query. I wonder why the difference in behaviour.

Sanjiv


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.