0
|
I am trying to develop a demo to cement my understanding of the REPEATABLE_READ isolation level. I have tried demos using hibernate and jdbc. JDBC works as expected, however hibernate does not.
My expectation is that, if i read a database row within one session, and i try to write the same row from another session, it should block until the first session finishes.
Hibernate:- When i 'get' an object (row) in Thread 0 and sleep, and within Thread 1 we try to update the same object (row), Thread 1 should wait till Thread 0 commits.
hibernate.connection.url is jdbc:derby:isolation;create=true and hibernate.connection.isolation is 2. I make two objects of HibernateExample7_IsolationRR_Thread, and i create a scenario where Thread 0 gets the vehicle and sleeps for long time. Meanwhile Thread 1 tries to get and update Vehicle. It successfully commits even before Thread 0 commits.
Due to the REPEATABLE_READ isolation level, shouldn't T1 wait on a commit. If not then it's a READ_COMMITED isolation level not a REPEATABLE_READ isolation level.
| ||||||||
|
1
|
Your expectation is wrong. Repeatable read doesn't mean that a transaction should block while another transaction reads the same row. It means that reading the same row twice in the same transaction should return the same data, even if another transaction has committed a change to this row between the first and the second read.
You get that (more or less) for free with Hibernate, since the second read will return the data from the first-level cache, without going to the database at all.
Also, you're making your test with a database that doesn't support this isolation level:
| ||||||||||||||||||||
|