Repository navigation
Replies: 3 comments
|
@transactional(readOnly=true) 옵션을 설정하면 해당 트랜잭션은 CRUD 중 Read만 실행한다는 의미로, 데이터를 조회만 하고 변경하지 않다는 것을 약속하게 됩니다.
|
|
주된 이유로는 JAP를 사용할 때, 더티체킹(변경감지)에 대한 비용을 없앤다는 것 같습니다. 관련된 JPA코드인데 주석에 설명이 잘 되어있네요 if ( isReallyReadOnly ) {
//no need to take a snapshot - this is a
//performance optimization, but not really
//important, except for entities with huge
//mutable property
persistenceContext.setEntryStatus( entityEntry, Status.READ_ONLY );
}
else {
//take a snapshot
TypeHelper.deepCopy(
hydratedState,
persister.getPropertyTypes(),
persister.getPropertyUpdateability(),
//after setting values to object
hydratedState,
session
);
persistenceContext.setEntryStatus( entityEntry, Status.MANAGED );
}[주석 내용] readOnly일 경우에는 스냅샷이 찍을필요가 없고, 이렇게 함으로써 성능최적화가 된다. 라고 합니다. |
|
�JPA의 더티체킹이란, 트랜잭션이 끝나는 시점에 변화가 있는 모든 엔티티 객체를 데이터베이스에 자동으로 반영해줍니다. JPA는 스냅샷을 통해서 엔티티의 조회 상태를 찍어놓고, 변경 사항이 있다면 update 쿼리를 데이터베이스에 전달합니다. 하지만, |
Uh oh!
There was an error while loading. Please reload this page.
Spring에서 제공하는 트랜잭션 관리 어노테이션
@Transactional에는 readOnly라는 옵션이 있습니다.어떤 트랜잭션이 조회만 수행한다면 readOnly를 true로 설정하여 성능상 이점을 챙기라고 합니다.
이때 어떤 부분에서 성능상 이점이 존재하는지 궁금합니다.
All reactions