I've got problem with spring boot code. I'm trying to understand isolation levels with @Transactional annotation and given this code:
//BookingService class bookingService2 instance
@Transactional(isolation = Isolation.REPEATABLE_READ)
public String readConstantly() throws InterruptedException {
String name = "";
for(int i=0; i<2; i++) {
name = jdbcTemplate.query("select FIRST_NAME from BOOKINGS where ID=1", (rs, rowNum) -> rs.getString("FIRST_NAME")).get(0);
logger.info("Read name " + name);
Thread.sleep(1000);
}
return name;
}
and this code:
//BookingService class bookingService instance
@Transactional
public void updateOne(){
jdbcTemplate.update("update BOOKINGS set FIRST_NAME = ? where ID = 1", "zz");
}
With execution like that:
new Thread(() -> {
try {
bookingService2.readConstantly();
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
bookingService.updateOne();
I expect updateOne to wait until readConstantly transaction ends, but when i invoke it this is output:
2016-11-30 12:29:15.158 INFO 6456 --- [ Thread-3] hello.BookingService : Read name Alice
2016-11-30 12:29:16.158 INFO 6456 --- [ Thread-3] hello.BookingService : Read name zz
I try to understand why in this case isolation level don't do much work?