-->
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.  [ 1 post ] 
Author Message
 Post subject: Query Cache Problem/Extension?
PostPosted: Thu Sep 09, 2004 6:25 pm 
Newbie

Joined: Wed Sep 08, 2004 5:59 pm
Posts: 5
Hibernate version:2.1.6

Mapping documents: (Unless there really is a problem with my setup, this isn't really relevant.)

Code between sessionFactory.openSession() and session.close():(Unless there really is a problem with my setup, this isn't really relevant either.)

Name and version of the database you are using: MySQL (prolly not relevant)

After playing around with hibernate it appears that if you call Query.iterator() ( instead of Query.list() ) and Query.setCacheable(true), then hibernate will not perform query caching as requested. If this is expected, would it be possible to change hibernate to allow the query to be cached if Query.iterator() is called AND the end of the result set is reached? (P.S. In the mean time, I recommend adding to "14.5 The Query Cache" clearly stating that you must use Query.list() instead of Query.iterator(). It took me a little while to figure out that that was the problem. I kept thinking it was a problem with how I had ehcache configured.)

Does query caching only provide caching within a session? Meaning that the following pseudo code does not work.

for(int i=0; i<1000; i++) {
Session session = sessionFactory.openSession();
String queryStr = "from Account";
Query query = session.createQuery(queryStr);
query.setCacheable(true);
query.list();
s.closeSession();
}

From the tests that I have created the stuff above doesn't seem to work. If that's not the expected behavior, then I'll keep trying to make it work.

From a theoretical stand point, it seems like there shouldn't be too much difference between knowing whether a query has been invalidated because of data changes within a session versus more globally. e.g. in the above example, as long as no accounts were added or deleted (save() or delete()), we shouldn't have to go to the database again. Or more generally as long as no objects associated with the query has had a save(), update(), or delete() called on them, it should be safe to continue caching the query as long as no outside application changed data affecting the results of the query. By "association" I mean that a object is associated with a query by class type when that same class is referenced in the "from" or "where" clause or is in a subselect of the query.

It also seems like it would be appropriate to not automatically invalidate queries between sessions if the data is solely being pulled from objects who's mapping file contains "<cache usage="read-only"/>" and the criteria also stays within "read-only" objects/tables.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.