-->
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: Enable cache for read queries.
PostPosted: Sun Oct 12, 2008 11:20 pm 
Newbie

Joined: Sun Oct 12, 2008 11:15 pm
Posts: 4
Hello,

I have developed a website having registration and search functionality. User can search for a variety of a parameters. How can I use hibernate cache for data read queries.

Ex:
<![CDATA[from PersonalInfoBean c WHERE (c.year >= ? and c.year <=?) and (c.height >= ? and c.height <=?) and c.gender = ? and enable='Y' ORDER BY lastLoginTime DESC) ]]>

I am already using
query.setCacheable(true);
query.setCacheRegion("query." + queryString);

Thanks
!TechByte


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 13, 2008 12:57 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
You would also need some ehcache.xml configuration file (or other caching library of your preference). If none found, Hibernate uses the default, which is included in its jar.

Note that query caching might not be very useful in your case, since it is mostly used in cases where few queries with the same parameters are executed. Your case is the opposite: that query can adopt a wide combinatory of parameters!
The cache will store only so many pairs "combination of parameters-resultset" before running out of space.

I don't think it makes much sense naming extra cache regions after your queries' SQL code. Either don't define any region, or use something more meaningful. Also notice that those eccentric "regions" would not be defined in the default cache configuration file ehcache.xml

_________________
Gonzalo Díaz


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.