Transaction Manager 3/ 패스트캠퍼스 챌린지 17일차
3009 단어 SpringbootSpringboot
Isolation Annotation
Test
@Test
void isolationTest(){
Book book = new Book();
book.setName("JPA강의");
bookRepository.save(book);
bookService.get(1L); //DB를 지우고 바로 테스트를 하기 때문에 book의 정보가 1번
System.out.println(">>> " + bookRepository.findAll());
}
BookService.java
@Transactional(isolation = Isolation.READ_UNCOMMITTED) //지정
public void get(Long id){
System.out.println(">>> "+bookRepository.findById(id));
System.out.println(">>> "+bookRepository.findByAll());
System.out.println(">>> "+bookRepository.findByAId(id));
System.out.println(">>> "+bookRepository.findByAll());
}
sql
mysql> start transaction;
Query Ok, 0 rows affacted (0.00sec)
mysql> update book set category='none';
Query Ok, 0 rows affacted (0.00sec)
Rows matched: 1 Changed: 1 Warnings:0
result
-> debug로 get()의 두번째 컬럼까지 실행결과 (Dirty Read)
중간에 업데이트 구문을 하나 추가해서 실행
sql
mysql> rollback;
Query Ok, 0 rows affacted (0.00sec)
BookService.java
@Transactional(isolation = Isolation.READ_UNCOMMITTED) //지정
public void get(Long id){
System.out.println(">>> "+bookRepository.findById(id));
System.out.println(">>> "+bookRepository.findByAll());
System.out.println(">>> "+bookRepository.findByAId(id));
System.out.println(">>> "+bookRepository.findByAll());
Book book = bookRepository.findById(id).get();
book.setName("바뀔까?");
bookRepository.save(book);
}
- 코드실행
sql
mysql> start transaction;
Query Ok, 0 rows affacted (0.00sec)
mysql> update book set category='none';
Query Ok, 0 rows affacted (0.00sec)
Rows matched: 1 Changed: 1 Warnings:0
result
Dirty Read 후 Update쿼리가 생성되었음
코드가 종료 되지 않고 대기상태로 전환
sql
mysql> commit;
Query Ok, 0 rows affacted (0.00sec)
다음 브레이크 포인트로 이동됨, 디버깅 계속 진행
다음과 같이 name이 바뀔까?로 변경된걸 확인할 수 있다.
#패스트캠퍼스 #패캠챌린지 #직장인인강 #직장인자기계발 #패스트캠퍼스후기 #한번에끝내는Java/Spring웹개발마스터초격차패키지Online
본 포스팅은 패스트캠퍼스 환급 챌린지 참여를 위해 작성되었습니다.
Author And Source
이 문제에 관하여(Transaction Manager 3/ 패스트캠퍼스 챌린지 17일차), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@mangojuice/Transaction-Manager-3-패스트캠퍼스-챌린지-17일차저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)