-->
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: Incrementing values of a column
PostPosted: Fri Nov 10, 2006 2:24 pm 
Newbie

Joined: Thu May 18, 2006 1:46 pm
Posts: 10
Hello there! We have a very concurrent application. Our entity have a value that is incremented by one every time it is updated. We ran in a concurrency problems here.

The code is as follow:

Entity entity = dao.get(pk);//ensure that we have the last persisted one
entity.setValue(entity.getValue()+1);
dao.update(entity);

I guess you guys figured out what's going on... we are reading stale data, a user reads value 123 for example, and just before he updates with value 124, another user already did, now, something that should be 125 is 124.

We could add synchronize to our java method, but this may lead to bottlenecks. Also we could use triggers (but we don't want to have this kind of rules in the DB).

Does hibernate provide a way of doing this? I was thinking about Interceptors, are they thread safe?

Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 10, 2006 5:17 pm 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
http://www.hibernate.org/hib_docs/v3/re ... optimistic

The column type you are describing maps directly to a 'version'. There are quite a bit of resources on the web with how to handle optimistic concurrency control. Start with the link above.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.