1 Reply Latest reply: Mar 24, 2012 11:15 PM by Adam Warski RSS

Hibernate Concurrency problem

Anirban Gupta Newbie

Hi,

 

I was not finding a suitable place for this question and so decided to put it here. I have a problem with concurrency control in hibernate. As it happens in databases, the transaction data are read from databases by issuing a read lock on the database column to be read, and obtaining a write lock when the data is to be stored. But what happens in hibernate is the the column data alon with the version number (or timestamp, both of which are used only for concurrency control) are read, the data can be changed in the application and while updating, it updates the column only if the version number retrieved previously and that while updating match. Else the data is discarded. So unlike in database scenario, this can be annoying because an application may read a column data an can spend uncertain amount of time executing its business logic. In the meantime, another transaction may read and update the same column data thus incresing the version number and when the previous transaction goes to commit the column data, it fails. My question is can this type of scenario prevented?

 

Regards,

Anirban.