-->
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: Does query cache work with query.setMaxResults()?
PostPosted: Fri Mar 25, 2005 3:36 pm 
Beginner
Beginner

Joined: Mon May 24, 2004 7:39 pm
Posts: 37
Location: Charlotte
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.8


Hello, I am using the MySQL dialect with query cache enabled. I have show SQL set to true.

I have noticed that if I do not call query.setMaxResults(), the SQL does not print to the console (because it wasn't run since it was found in 2nd level cache). However, if I use the same query but call query.setMaxResults(10), the SQL does print out so, it is being called again.

Is there anything I can do to make query cacheing work in conjunction with setMaxResults? Any help would be greatly appreciated. Thank you very much.

Joe


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
without being able to check the code right now i would guess that the value of maxresults is used as part of the key to identify what result the query matches too.

what happens if you execute the same query wiuth the same maxresult - is it still executed ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 5:16 pm 
Beginner
Beginner

Joined: Mon May 24, 2004 7:39 pm
Posts: 37
Location: Charlotte
Thanks very much for the reply Max.

I was actually wrong with my previous message, this is what it really is..
Performing query.list() does listen to the cache and performing query.scroll() does not.

Here is a simple little example:
Code:
      System.out.println("I'm checking the first query..");
      Query query = getNamedQuery(QUERY_MESSAGE_BOX_MESSAGES, messageBox
            .getId());
      query.setCacheable(true);
      query.list();
      
      System.out.println("I'm checking the second query..");
      query = getNamedQuery(QUERY_MESSAGE_BOX_MESSAGES, messageBox
            .getId());
      query.setCacheable(true);
      query.scroll();


And, here is the output:
Code:
16:10:58,779 INFO  [STDOUT] I'm checking the first query..
16:11:02,092 INFO  [STDOUT] I'm checking the second query..
16:11:05,561 INFO  [STDOUT] Hibernate: select message0_.message_id as message_id, case when message0__1_.voice_message_id is not null then 1 when message0__2_.email_message_id is not null then 2 when message0_.message_id is not null then 0 end as clazz_, message0_.status as status25_, message0_.created_date as created_3_25_, message0_.storage_size as storage_4_25_, message0_.message_box_id as message_5_25_, message0__1_.message_length as message_2_26_, message0__1_.from_phone_number as from_pho3_26_, message0__2_.text_data as text_data27_, message0__2_.from_address as from_add3_27_, message0__2_.from_name as from_name27_, message0__2_.subject as subject27_, message0__2_.is_html as is_html27_ from message message0_ left outer join voice_message message0__1_ on message0_.message_id=message0__1_.voice_message_id left outer join email_message message0__2_ on message0_.message_id=message0__2_.email_message_id, message_box messagebox1_ where (message0_.message_box_id=? )and((messagebox1_.greeting_id is null  and message0_.message_box_id=messagebox1_.message_box_id)or(messagebox1_.greeting_id<>message0_.message_id  and message0_.message_box_id=messagebox1_.message_box_id)) order by  message0_.created_date desc


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 25, 2005 5:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i dont think scroll() should use the cache since it should return a scrollable resultset to you ....and that we need to fetch from the db.

_________________
Max
Don't forget to rate


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.