2023-11-18
1. 원인
Spring를 빌드하다 보면 아래와 같은 WARN 이 뜨는 경우가 있다.
JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
해당 부분을 살펴보자. OSIV(View의 Open Session)는 그림과 같이 View 계층이 프록시 초기화를 트리거할 수 있도록 지속성 콘텍스트를 열어두도록 강제한다. 쉽게 표현하자면 JPA의 영속성 콘텍스트가 트랜잭션의 범위를 넘어 View까지 생존해 있는 것을 말한다.
즉 서비스 단에서의 트랜잭션 동작은 마무리되어 명시적인 트랜잭션 동작이 없음에도 불구하고 UI 렌더링 단계에서 발행된 모든 추가 명령문은 자동 커밋 모드에서 실행될 가능성이 있기 때문에 DB에 부담을 줄 수 있게 된다.
2. 해결 방법
사실 해결 방법은 간단하다. 자신의 설정파일에 해당 기능을 false 처리하면 된다.
properties
spring.jpa.open-in-view=false
yaml
spring:
jpa:
open-in-view: false
3. 참고자료
What is this spring.jpa.open-in-view=true property in Spring Boot?
I saw spring.jpa.open-in-view=true property in Spring Boot documentation for JPA configuration. Is the true default value for this property if it's not provided at all?; What does this really do? ...
stackoverflow.com
https://vladmihalcea.com/the-open-session-in-view-anti-pattern/
The Open Session In View Anti-Pattern - Vlad Mihalcea
Open Session in View is an Anti-Pattern, and this post is going to demonstrate why it is so.
vladmihalcea.com