1

Some entities on my application needs to be locked during the scope of a certain transaction. I need to lock all the entities that take part in the transaction and would't like to create special methods for locking the entities on my DAO. I am using spring's declarative transaction and set the isolation level for that particular method call, but when the data are fetched the generated SQL query, is a normal SELECT and not a SELECT XXX FOR UPDATE. Do I have to manually specify the lock on each participating entity on the transaction on hibernate? Shouldn't this be controlled from the transaction isolation? When setting the lock mode to UPDATE on hibernate's session I can see the correct query, does that mean that I need to manually specify the lock even though I have already specified the isolation.

Best

maxsap
  • 2,971
  • 9
  • 44
  • 70

1 Answers1

0

Yes. Isolation level and locking are different things, and for sure locks will not be controlled from the transaction isolation. Additionallky i would advice you not play with isolation level unless you have a very good reason.

You should use pessimistic locking when querying to apply SELECT ... FOR UPDATE on the selected entities.

This would help you

Spring Pessimistic locking

Community
  • 1
  • 1
Rafael
  • 2,521
  • 2
  • 33
  • 59