-->
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: How to optimistically lock a DomainObject graph?
PostPosted: Wed Jan 28, 2004 11:06 am 
Newbie

Joined: Thu Jan 15, 2004 7:22 am
Posts: 3
Is there a way to ensure that a DomainObject graph i.e. a Parent with a collection of children is versioned as a single unit.

Hibernate seems to increment the parent version when a child is added/removed from the parent collection. However it doesn't seem to do so if a child is updated.

Was there a reason this was not done? Because its possible to break Parent-level invariants when concurrently updating a child. e.g. consider the foll object graph:

---------------
Order (invariant: sum of prices of all items should be less than $1000)
|--- OrderItem A - $350, Quantity 1
|--- OrderItem B - $200, Quantity 1
(Total: $550)

- Now 2 users load this Order object at the same time.
- The first user updates the quantity of 'OrderItem A' to 2 and saves the Order
- Simultaneously, the second user updates the quantity of 'OrderItem B' to 2 and saves the Order

Both these updates would go through fine, since different records/objects were updated; however the database is now in an inconsistent state because the invariant at the Order level is broken (the order total is $1100).
---------------

Has anyone come across such a situation? Or is it rare enough that it's ok to ignore?

Is there a way to handle such a situation in Hibernate. We are thinking of incrementing the Parent object's version in an Interceptor whenever a child is updated. Would this cause any other problems? Is there another way?

Thanks,
-Yogi


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 2:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
For a collection marked inverse="true", versioning applies to the children only

For a collection with inverse="false" (the default), versioning applies to the collection owner


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.