-->
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: Best Practise for Updating Static Properties
PostPosted: Tue Dec 27, 2005 2:20 am 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
I'm just wondering what the best practise for updating a static property of an object is. The thing I'm worried about is concurrency. For example, a Product object might have a quantity property. When this Product is purchased you, would decrement the quantity property by 1. However, if you simply quantity-- and save the object you could have problems. Imagine Product1 was loaded and Product2 was loaded at the same time. The quantity at this point is 35. Product1 is saved so quantity goes down to 34. Now Product2 is saved. If it's quantity is 35 and decremented, then the quantity is 34. In reality the quantity should be 33. Do you just write custom sql to take care of cases like this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 4:56 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
Yes, you are right - it's better to accomplish with custom SQL statement executed in the scope of the same transaction, which inserts/updates other purchase-related records.

Perhaps, you can also start transaction, then load your object with the property you need to update, ensuring that its record is locked in the DB, then change property, save object and commint transaction. Maybe it's achievable by using LockMode.Upgrade, but i'm not sure, because haven't tried.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 1:31 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
I would consider handling this either through the NHibernate interceptor or through a database trigger.


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.