-->
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.  [ 3 posts ] 
Author Message
 Post subject: Question about concurrent modifications
PostPosted: Thu Oct 14, 2004 3:17 pm 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Hello everyone,

Hibernate version: Hibernate 2.1.3
Name and version of the database you are using: MySQL 4.0

In my web-application, I today observed the event of two concurrent requests modifying the same persistant object (but different properties/columns) at neary the same time. The result was that the "second" request has undone the changes of the "first".

This is no wonder, since I configured the 2nd level cache to use the "nonstrict-read-write" strategy.

My question is if the only thing I have to do to prevent this error in the future is to switch to "read-write" strategy?

I am using MySQL 4.0 and the table in question is using MyISAM.
The 2nd level cache is an EHCache 0.7.
I have set "hibernate.connection.isolation" to 4.
My application uses the Open Session in View pattern (with the Spring filter).
My application is not clustered.

Regards,

Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 3:19 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats most likely not a caching problem (though you should know what it does before enabling some random concurrency strategy), but a problem tha can be solved using optimistic locking and automatic versioning. Check the documentation.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 15, 2004 4:04 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
Since my application does not use any "long transactions", does the use of automatic versioning make any sense here?

Maybe I would just need to load my persistant object with FOR UPDATE (LockMode.UPGRADE) in my updating methods.

The methods in question look like this:

Code:
public void setName(int catId)
{
Cat cat = Session.load(Cat.class, catId);
cat.setName(...);
}
public void setSex(int catId)
{
Cat cat = Session.load(Cat.class, catId);
cat.setSex(...);
}


The problem I described in the original post was caused by one thread calling setName and the other calling setSex at the same time.

Is it advisable to use LockMode.UPGRADE in these situations?

Would LockMode.UPGRADE have any effect if I continue to use MySQL 4.0 and MyISAM tables?

Regards,

Andreas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.