@Transactional에 대한 이해가 부족함을 느낌
$ 우선 Propagation
- REQUIRED(TransactionDefinition.PROPAGATION_REQUIRED) - Default
- Support a current transaction, create a new one if none exists
- Exception 발생시 부모/자식 모두 rollback
- SUPPORTS(TransactionDefinition.PROPAGATION_SUPPORTS)
- Support a current transaction, execute non-transactionally if none exists
- Transaction이 없어도 메서드는 정상 동작
- MANDATORY(TransactionDefinition.PROPAGATION_MANDATORY)
- Support a current transaction, throw an exception if none exists
- 부모 Transaction이 있어야 함
- REQUIRES_NEW(TransactionDefinition.PROPAGATION_REQUIRES_NEW)
- Create a new transaction, and suspend the current transaction if one exists
- 부모/자식 각각 rollback, 자식에서 예외 발생시 부모는 예외 처리 전까지만 commit
- NOT_SUPPORTED(TransactionDefinition.PROPAGATION_NOT_SUPPORTED)
- Execute non-transactionally, suspend the current transaction if one exists
- SUPPORT하지 않음
- NEVER(TransactionDefinition.PROPAGATION_NEVER)
- Execute non-transactionally, throw an exception if a transaction exists
- NESTED(TransactionDefinition.PROPAGATION_NESTED)
- Execute within a nested transaction if a current transaction exists, behave like REQUIRED otherwise
- 부모에서 예외 발생시 자식도 rollback, 자식 예외 발생 시 부모는 예외 처리 전까지만 commit
- JDBC의 savepoint 기능 사용, DB가 savepoint 지원시 사용 가능(ex. Oracle), JPA 사용불가
$ Isolation - 동시에 실행되는 Transaction간 격리 수준 정의
- READ_UNCOMMITTED(TransactionDefinition.ISOLATION_READ_UNCOMMITTED)
- A 데이터 수정 -> B 조회 수정된 데이터 -> A 롤백 -> B dirty read 발생
- READ_COMMITTED(TransactionDefinition.ISOLATION_READ_COMMITTED)
- A 데이터 수정 -> B 조회 수정전 데이터 -> A 커밋 -> B 조회 수정된 데이터
- REPEATABLE_READ(TransactionDefinition.ISOLATION_REPEATABLE_READ)
- A 데이터 조회 수정전 데이터 -> B 데이터 수정(not commit), 조회시 수정된 데이터 -> A 데이터 조회 수정전 데이터
- SERIALIZABLE(TransactionDefinition.ISOLATION_SERIALIZABLE)
- Transaction이 종료될 때까지 모든 데이터에 shared lock이 걸림