-->
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.  [ 1 post ] 
Author Message
 Post subject: Concurrency for not updated instances
PostPosted: Thu Jun 10, 2004 10:00 pm 
Newbie

Joined: Wed Jun 09, 2004 11:13 am
Posts: 4
Suppose I have

Country
Id
CanISellProductsToThisCountry

Order
Id
Country

Before adding an order I want to check if I can sell products to the country, so I ask

if (!order.getCountry().getCanISellProductsToThisCountry())
throw new Exception("You cannot order");

session.save(order);

The problem is that I really need to be sure that noone changed the CanISellProductsToThisCountry field since the moment I checked it to the moment the data is commited.

Can I have optimistic concurrency on the CanISellProductsToThisCountry field?

Do I need to do a session.lock() when reading the country to make sure noone changes it and then check it?

Note that if I need to do the latter I need to do that check when I'm in the context of a session, so I cannot put it in another place of my domain model (for example, when setting the order's country).

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.