각각 커넥션 풀에서 커넥션을 가져와서 사용하는 경우
@Test
void double_commit() {
log.info("트랜잭션1 시작");
TransactionStatus tx1 = txManager.getTransaction(new DefaultTransactionAttribute());
log.info("트랜잭션1 커밋");
txManager.commit(tx1);
log.info("트랜잭션2 시작");
TransactionStatus tx2 = txManager.getTransaction(new DefaultTransactionAttribute());
log.info("트랜잭션2 롤백");
txManager.rollback(tx2);
}
Hikari 커넥션 풀이 반환해주는 커넥션을 다루는 프록시 객체의 주소가 트랜잭션1, 2 각각 서로 다른 것을 확인할 수 있다.
conn0
커넥션은 동일하나 각각 따로 가져와서 사용하기 때문에 독립된 트랜잭션으로 동작한다. → 커밋을 하든 롤백을 하든 서로 영향 주지 않음
hello.springtx.propagation.BasicTxTest : 트랜잭션1 시작
o.s.j.d.DataSourceTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
o.s.j.d.DataSourceTransactionManager : Acquired Connection [HikariProxyConnection@1071570490 wrapping conn0: ..
..
hello.springtx.propagation.BasicTxTest : 트랜잭션2 시작
o.s.j.d.DataSourceTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
o.s.j.d.DataSourceTransactionManager : Acquired Connection [HikariProxyConnection@405804899 wrapping conn0: ..
전체 트랜잭션을 묶지 않고 각각 관리하기 때문에, 트랜잭션 1에서 저장한 데이터는 커밋되고, 트랜잭션 2에서 저장한 데이터를 롤백된다