Closed kjsu0209 closed 3 years ago
https://www.marcobehler.com/guides/spring-transaction-management-transactional-in-depth 에 따르면 아래 두 코드는 동일하다고 합니다.
`public class UserService {
public Long registerUser(User user) {
Connection connection = dataSource.getConnection(); // (1)
try (connection) {
connection.setAutoCommit(false); // (1)
// execute some SQL that e.g.
// inserts the user into the db and retrieves the autogenerated id
// userDao.save(user); <(2)
connection.commit(); // (1)
} catch (SQLException e) {
connection.rollback(); // (1)
}
}
}`
`public class UserService {
public Long registerUser(User user) {
Connection connection = dataSource.getConnection(); // (1)
try (connection) {
connection.setAutoCommit(false); // (1)
// execute some SQL that e.g.
// inserts the user into the db and retrieves the autogenerated id
// userDao.save(user); <(2)
connection.commit(); // (1)
} catch (SQLException e) {
connection.rollback(); // (1)
}
}
}`
더 자세한 내용은 잘 모르겠습니다... 죄송합니다 ㅎㅎ;
트랜잭션 매니저로 트랜잭션 범위를 설정하기 위해
DefaultTransactionDefinition
과TransactionStatus
를 설정하고, 롤백, 커밋은 transactionManager에서 메서드를 호출하는 방식으로 사용됩니다.그럼
@Transactional
은 원래 트랜잭션 매니저로 설정하기 위해 작성해야 했던 코드를 AOP로 간편하게 쓸 수 있게 만든 건가요? 둘의 내부 작동 방식이 같은지 궁금합니다 👀