Senior |
|
Joined: Tue Oct 28, 2008 10:39 am Posts: 196
|
Have a look at different locking strategies. I'd recommend to use the @Version-Annotation and an optimistic locking mechanism. Hibernate increments a version-field or a timestamp to recognize changes made by different sessions.
update xy set field1 = ? where id = ?;
becomes
update xy set field1 = ?, version = ? where id = ? and version = ?;
If another session changed data concurrently the second session will update no rows. As hibernate knows that there must be exactly ONE row it throws an exception you can handle. E.g. inform the user that the item is reserved for another user.
|
|