• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

concurrent update issue

 
VenuGopal Thati
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a table with optimistic versioning implemented using hibernate. one row in this table can be updated by more than one transaction at the same time and this update method is in stateless session bean. Issue here is when users are working on application at peak time, three to four transactions trying to update same row and database allows update for first transaction and other transactions getting versioning error (This works as per the implementation). Because of this user's operations are getting delayed and they have to repeat same process until database allows update.

Is there anyway to allow updates from multiple transactions with optimistic versioning in place ? please suggest.

Thanks in Advance.
 
Jayesh A Lalwani
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, don;t do optimistic locking. However, you might run into problem of one transaction overwriting another transaction's changes

 
VenuGopal Thati
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayesh,

If I don't do optimistic locking data will be corrupted. Thanks for your response.
 
Jayesh A Lalwani
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, exactly. THe only way to prevent data corruption is to prevent 2 transaction from updating a record concurrently. Optimistic locking is the mechanism that you use. If you allow 2 transactions to update the record at the same time, you will always have the possibility of data corruption, no matter what you do



 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Optimistic locking is used when it is unlikely that the same row is going to be modified by many transactions concurrently. I think that you should use pessimistic locking instead. Just get the entity with LockMode.PESSIMISTIC_WRITE and other transactions will have to wait for the lock release.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic