-->
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: Detached Query causes stale query cache entries
PostPosted: Tue Aug 12, 2008 2:44 pm 
Newbie

Joined: Tue Aug 12, 2008 2:31 pm
Posts: 1
Hibernate version:
3.2.6

We ran into an issue where detached query causes stale query cache entries. Our example is to retrieve a list of our favorite dogs. We use a separate table called favorite_animal to store our favorite animals, including dogs.

For example, our main query is the following,

from Dog

And we use a detached query to select our favorite Dog,
select fa.animal_id from favoriate_animal fa where fa.user_id = :user_id

The combined SQL looks like the following,
from Dog dog where dog.id in (select fa.animal_id from favoriate_animal fa where fa.user_id = :user_id)

There is our problem. We execute the above query once and get a list of dogs back. We then remove one dog from our favorite list and then run the above query again. We are expected to see one less dog in our result but we got the same list as before!

It turns out that the query cache entry was not invalidated when we removed one dog from the favorite list. I dug a little and it seems like the query spaces used to look up invalidated entity names are only built from associated criteria, but not from detached query or detached query based criterion.

In our example, the query spaces will only contain [DOG] entity.

I had made some changes to CriteriaQueryTranslator to include additional query spaces from detached queries in getQuerySpaces method in CriteriaQueryTranslator but want to make sure that I am on the right track.

After my fix, the query spaces will contain [DOG,FAVORITE_ANIMAL].

Thanks for your feedback and comments.
-- Lei


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.