Good Morning! I am having an interesting problem running some integration tests in my local that maybe is something that you must be aware of. We have a public method with a @Transactional annotation (@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)). Inside that method, we are calling another method with the annotation @Transactional(propagation = Propagation.MANDATORY), and we are checking the isolation level performing a query "select @@tx.isolation", if the query is different than READ-COMMITED we throw an error:
Spring version: 5.3.23
Let's say:
@Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)
public void example(){
xClass.yExample();
}
public xClass(){
@Transactional(propagation = Propagation.MANDATORY)
public void yExample(){
final String isolationLevel = jdbcTemplate.queryForObject("select @@tx_isolation", String.class);
if (!isolationLevel.equals("READ-COMMITTED")) {
throw new IllegalStateException("Invalid isolation level: " + isolationLevel);
}
}
}
-
when you run from the beginning of the local database and launch the SELECT you get this: @@GLOBAL.tx_isolation -> REPEATABLE-READ @@SESSION.tx_isolation -> REPEATABLE-READ @@tx_isolation -> REPEATABLE-READ
-
If you set a breakpoint in the query that we launch to get the isolation value value @@GLOBAL.tx_isolation -> REPEATABLE-READ @@SESSION.tx_isolation -> READ-COMMITTED @@tx_isolation -> READ-COMMITTED
IT WORKS OK UNTIL NOW
-
Change the @Transactional's isolation, I am changing Isolation.READ-COMMITED by Isolation.REPEATABLE_READ @@GLOBAL.tx_isolation -> REPEATABLE-READ @@SESSION.tx_isolation -> REPEATABLE-READ @@tx_isolation -> REPEATABLE-READ
-
If you set the isolation again to READ-COMMITED (you have the same configuration as the previous second point but with different results: @@GLOBAL.tx_isolation -> REPEATABLE-READ @@SESSION.tx_isolation -> REPEATABLE-READ @@tx_isolation -> REPEATABLE-READ
-
However, after clean install it takes the correct isolation level.
Comment From: snicoll
However, after clean install it takes the correct isolation level.
Sorry I am not sure what you mean by that. IF you mean that it breaks in your IDE but not when the app is invoked from the command line, there's not much we can do. I am going to close this but if you're still affected and can share a small sample that breaks consistently, we can reopen.