0

I am not sure in understanding the Database Locks. I am using the repeatable read isolation level. According to wikipedia it keeps read and write locks (acquired on selected data) until the end of the transaction. Let's consider the following scenario: "Let's have two threads A, B. Thread A begins a transaction. Let's say thread A retrieves a list of all users from table User. (I am expecting here that: Thread A acquired read&write locks on all users ??) Thread B begins another transaction, retrieves one concrete User u from table User and updates the User u then commits the transaction (Since A acquired the locks, does the Thread B has to wait until A commits the transaction ??)"
Is the describes behavior to expect if using JPA ?
Is the lock acquired if the Thread A reads the users outside a transaction (Let's say if I am using the Extended Peristence Context) ??

FilipR
  • 1,218
  • 4
  • 22
  • 39

1 Answers1

0

You are confusing the logical isolation level with its physical implementation. The SQL standard defines the four isolation levels Serializable, Repeatable Read, Read Committed and Read Uncommitted and the three ways in which serializability might be violated: dirty read, nonrepeatable read and phantom read.

How a particular DBMS achieves each level of isolation is an implementation detail which differs between each DBMS. Some DBMS may use a locking strategy which means that read locks are used that means writers are blocked until a transaction completes. Other DBMS may use other strategies, such as multi-version concurrency control, which means readers and writers do not block each other. In order to maximize the performance and scalability of your application you will need to code to the particular implementation of the DBMS you are using.

DrabJay
  • 2,989
  • 2
  • 13
  • 12
  • Thank you for your answer! So if I want to achieve some isolation level and I am using JPA to work with my MySQL DB the only things I can use is the pessismistic and optimistic locking and based on that the isolation level will be set (PESSIMITIC_READ - repeable read isolation level is set, OPTIMISTIC - read commited) ? – FilipR Jul 23 '15 at 10:13
  • I am afraid I am not sufficiently knowledgeable of how JPA or MySQL implement isolation levels to comment on the best strategy to use with that combination of applications. – DrabJay Jul 23 '15 at 12:05