-->
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 invalidation when querying by ID
PostPosted: Mon Jan 23, 2006 9:50 pm 
Hibernate Team
Hibernate Team

Joined: Mon Jan 23, 2006 9:18 pm
Posts: 14
Hibernate version: 3.0.5

Hi all,

I'm running into a query cache issue using a Criteria object with the
criterion, Restrictions.idEq(). The Criteria is created as follows:

User user = (User) session.createCriteria(User.class)
.add(Restrictions.idEq(1))
.setFetchMode("groups", fetchMode)
.setCacheable(true)
.setCacheMode(CacheMode.NORMAL)
.uniqueResult();

I am using a Criteria rather than Session.load() or Session.get() so
that the fetch mode can be set dynamically.

I can see from the logs that the query and result set are cached in
StandardQueryCache. The result set is properly returned from the cache
until the timestamp for User is updated in UpdateTimestampsCache when
a User entity is created, updated, or deleted. At this point, the
timestamp for the result set in StandardQueryCache precedes the
timestamp in UpdateTimestampsCache, making the result set out-of-date.
The result set is obtained from the database and is then re-cached
with the query and updated timestamp in StandardQueryCache.

I noticed there is an optimization where querying by natural ID can
avoid this cache invalidation, but there doesn't seem to be one for
querying by the actual id. Am I missing something? Is there a reason
not to do this?

Thanks for your help!


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.