-->
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.  [ 3 posts ] 
Author Message
 Post subject: Speed your queries with setCacheable(true)
PostPosted: Thu Jul 01, 2004 1:46 am 
Newbie

Joined: Thu Sep 25, 2003 12:45 am
Posts: 14
Location: Hannover, Germany
Hi there,

a common problem of low performance are repeated queries which give the same result each time. For example:

Query q = session
.createQuery("from artikel in class Artikel where lower(artikel.isbn) = ?");
q.setString(0,_isbn);
...
return artikel.getId();

Insted of repeating the same query every time an getting the same result from database, you can simply cache it. Do not forget to set a cache region for this specific query. The following example code caches the result:

Query q = session
.createQuery("from artikel in class Artikel where lower(artikel.isbn) = ?")
.setCacheable(true)
.setCacheRegion("getArtikelId_"+_isbn);


As you can see we use method name and query parameter to cache this result automatically by hibernate. Next time your application is looking for the same ISBN, the result is only fetched from hibernates cache. If you like refetch it directly from database, simply add an additional value to cacheregion. My suggestion is to use a timestamp as addition string in those cases.

This improvement has speed up our repeating application calls up to factor 1.000 %, so it is really worth to try it :-))


Andreas Bednarz
id-on GmbH, Hannover Germany
bednarz((@))id-on.de
www.id-on.de

_________________
:-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 29, 2004 4:42 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
Why do you use a distinct cache region for each ISBN, as opposed to just dedicating a cache region for any execution of this query? Indeed, unless you have special cache expiration policies for these queries, why is a special cache region needed at all?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 29, 2004 5:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If the query result is put into the cache, the key includes the query parameters, so there is really no need to include the isbn in the region.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.