Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- euclideanalgorithm
- boj10775
- BFS
- TDD
- boj10942
- boj2239
- boj2252
- DynamicProgramming
- onTouch
- boj15654
- react
- DP
- boj15998
- BOJ
- boj_15685
- boj15954
- django
- 동적계획법
- nestedjson
- bruteforce
- onTouchListner
- boj15683
- DFS
- boj_15684
- testdb
- mysql
- springboot
- backtracking
- Spring
- boj7579
Archives
- Today
- Total
이마닷의 블로그
[TIL] 240701 본문
JPA transaction
Spring app에서 전체 configuration 상에 기본 transaction manager를 명시 후, 이후 app 내에서 별도의 transaction manager를 설정하지 않은 채 기본 transaction manager와 다른 연결 정보를 가진 entity에 접근할 때,
- 해당 엔티티에 대한 JPA 메서드는 트랜잭션 속성 기본값으로
PROPAGATION_REQUIRED
(새로운 transaction 생성),ISOLATION_DEFAULT
를 가지고 실행된다. - 새로 생성된 트랜잭션은 해당 JPA 메서드가 실행된 맥락과 상관없이 메서드 실행 즉시 commit 되지만, 실행된 맥락(?) 상의 로직이 실패하는 경우(ex. exception 발생, 메서드 중도 실행 중단 등) 당연히 rollback 된다
- 해당 엔티티에 대한 JPA 메서드는 트랜잭션 속성 기본값으로
@Transactional
어노테이션의readOnly
옵션을true
로 세팅하면JPA session flush 모드가
MANUAL
로 설정되고, 이 경우 flush를 수동 수행하지 않는 한 수정 내역이 DB에 반영되지 않는다.// HibernateJpaDialect.prepareFlushMode @Nullable protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException { FlushMode flushMode = (FlushMode)ReflectionUtils.invokeMethod(getFlushMode, session); Assert.state(flushMode != null, "No FlushMode from Session"); if (readOnly) { if (!flushMode.equals(FlushMode.MANUAL)) { session.setFlushMode(FlushMode.MANUAL); return flushMode; } } else if (flushMode.lessThan(FlushMode.COMMIT)) { session.setFlushMode(FlushMode.AUTO); return flushMode; } return null; }
JPA 내부적으로 dirty checking을 하기 위한 snapshot을 따로 보관하지 않으므로 메모리가 절약된다.
'TIL' 카테고리의 다른 글
[TIL] 240611 (0) | 2024.06.12 |
---|