-->
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: Problem with 2nd level cache eviction - and solution!
PostPosted: Sun Jun 22, 2008 11:03 am 
Newbie

Joined: Mon Jan 01, 2007 5:45 am
Posts: 4
Ok, this was a weird problem, but I finally soved it and decided I should post it here for others to see and use.

I am using ehcache for a simple 2nd level cache.
In my application I noticed that the cache gets evicted, even for entities that are not updated and should be read only. I have created a test, and found out that my cache gets evicted when I execute a native SQL update using createSQLQuery.
It doesn't matter which table I try to update, the entire cache was evicted and cleared!

After some debugging inside the Hibernate code, I found that hibernate creates a query spaces list, of all the entities that are part of the query. It appear that if you do not specify anything, all the entities end up in this list, which means that all the entities in the cache are cleared.

To solve it, I have added a call to the addSynchronizedQuerySpace() method on my SQLQuery instance, adding the actual table name I want to change. This solved my problem.

I do not know if this is a bug or a feature, but I have not found any documentation about this behavior.

Hope it helps someone.


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.