-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with level 2 cache and versioned objects
PostPosted: Tue Jun 26, 2007 10:40 am 
Newbie

Joined: Wed May 23, 2007 12:10 pm
Posts: 4
Hi all,

We are using hibernate 3.2.2 and ehcache 1.3. The cache provider class is net.sf.ehcache.hibernate.SingletonEhCacheProvider. We have a versioned object X that can get updated by concurrent user threads (via ajax calls in the real world). Without the second level cache on all is fine. StaleObjectStateException gets thrown and we can retry the add if appropriate. However, with the level 2 cache on things can go very wrong:

1 - Hibernate does a put into the cache of X with version 12 and then just after another thread does a put with version 11. The database version is therefore now 12 but the cache thinks its 11. This prevents the object being written to until the cache times out as the cache thinks its up to date.

2 - Hibernate does a put into the cache of X with version 12. The transaction that does the put gets rolled back because of some problem (potentially another thread adjusting object X). The database version is therefore still 11 but the cache thinks its 12. This prevents the object being written to until the cache times out as the cache thinks its up to date.

This is 100% reproducible in a test case that starts 5 threads and calls the add service.

Clearly I must be doing something stupid here as I don't believe that other people would not have seen this before but googleing and searching the forums have produced nothing so far...

Cheers in advance,

Dan


Top
 Profile  
 
 Post subject: RE: Problem with level 2 cache and versioned objects
PostPosted: Thu Jun 28, 2007 6:52 am 
Newbie

Joined: Wed May 23, 2007 12:10 pm
Posts: 4
We can produce a trivial test case to demonstrate this happening. It's simply a case of setting up multiple threads and initiating transactions within them to access a single versioned table. If need be, we can send this code as a zip.

We really need help with this as if it's not something we're doing wrong then it could be a major bug in Hibernate.

Cheers,

Dan.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.