Hello, We are using hibernate for a J2EE application,where we are updating multiple rows which could be shared other user.For example two user, user1 and user 2 read same 5 rows and displayed on User Interface. user1 and user2 selects same rows and try to update them in Database. How can we avoid one user updating the updates of other.
I can think of option below:
Option: while updating we will first fetch specific row as a persistant object (mark it as @version) in a hibernate transaction and update the same row using the same transaction. when other user tries to update the same he would check the @version value if it not matching, will throw exception.
Is this is the only way we can achieve optimistic concurrency or if there are other ways. Please suggest with sample code if possible.
Thanks!
|