-->
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: version control and multi-threaded model object modification
PostPosted: Sun Jan 24, 2010 6:44 pm 
Newbie

Joined: Thu Sep 10, 2009 3:03 pm
Posts: 5
I have added a version column to one of my model objects (and added the @Version tag). My application is multithreaded and when two threads try to modify the same model object in the same time, only one will succeed (which is what the versioning guarantees). Now, there are cases where the two threads are modifying two completely different columns and I would like that case not to fail with a StaleStateException.
- is having versioning not appropriate in this particular use case ?
- is there anyway to force hibernate to ignore the version number for a specific query ? (my query is changing one column which I know can be changed by only one thread, this assumption being guaranteed by design). Can the merge method be helpful in this case ?


Top
 Profile  
 
 Post subject: Re: version control and multi-threaded model object modification
PostPosted: Mon Jan 25, 2010 3:15 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I have been in a somewhat similar situation as you described. What I found worked best was to use an UPDATE statement that was executed against the database. See http://docs.jboss.org/hibernate/stable/ ... tch-direct for some more information.
I could use this because I knew that this particular property could only be updated by a specific piece of code.

You may also consider <class dynamic-update="true" optimistic-lock="dirty"> (or whatever the equivalent is with annotations). This is a more generic solution and will generate updates dynamically based on what properties that has changed.


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.