17日目Transaction Manager 3/Fastキャンパスチャレンジ
2960 ワード
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()を実行した2番目の列の結果
更新構文を中央に追加
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後に更新クエリーが作成されました
コードを終了せずに待機状態に切り替える

sql
mysql> commit;
Query Ok, 0 rows affacted (0.00sec)
次のブレークポイントに移動し、デバッグを続行
名前は変わりますか?に変更されたことを確認できます.

#クイックキャンパス#パカムチャレンジ#サラリーマン姜#職場人柄マシン脚#クイックキャンパス後期#使い捨て終了Java/spring Web開発Master超差パッケージオンライン
このレポートは、迅速なキャンパス税還付の課題に参加することを目的としています.
https://bit.ly/3FVdhDa
Reference
この問題について(17日目Transaction Manager 3/Fastキャンパスチャレンジ), 我々は、より多くの情報をここで見つけました https://velog.io/@mangojuice/Transaction-Manager-3-패스트캠퍼스-챌린지-17일차テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol