0

I have a scenario where I use a read on set of tables in a java service. I've annotated the service class @Transactional.

Is there any possible way to lock the corresponding rows I read, in all the tables I use, in my transaction and release it at the end of transaction ?

Ps: I'm using spring Hibernate, and I'm new to this locking concept. any material/ examples links would be of much help

Thanks

  • possible duplicate of [Spring @Transactional - isolation, propagation](http://stackoverflow.com/questions/8490852/spring-transactional-isolation-propagation) – Piotr Müller Sep 25 '13 at 13:32

1 Answers1

0

This depends on the underlying database engine and selected transaction isolation level. Some database systems do locking for reads, and some use MVCC, which means your updates won't be visible to other transactions until your transaction finishes and your transaction will operate on a snapshot of data taken at the start of the transaction.

So a simple answer is: choose appropriately high transaction isolation level (e.g. SERIALIZABLE) for your needs and a database engine that supports it.

http://en.wikipedia.org/wiki/Isolation_(database_systems)

Piotr Kołaczkowski
  • 2,601
  • 12
  • 14