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.
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
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.