Spring/JPA
-
N + 1 문제Spring/JPA 2023. 8. 6. 16:55
JPA는 테이블 간의 연관관계를 Mapping 해주는 ORM기술의 하나이다. JPA는 Java의 객체지향적 관점과 DB의 테이블 참조관계 사이의 불일치하는 부분을 해소하면서 원하는 데이터를 가지고 올 수 있게 해준다. Spring data jpa를 사용하면서 맞닥드릴 수 있는 N + 1 문제에 대해서 설명하고 해결 방법을 알아보자. Spring Data JPA JPA는 성능 최적화를 위해 지연로딩이라는 기술을 활용한다. 지연로딩이란, 관련이 있는 엔티티를 필요한 시점에 로딩하는 것을 말한다. 예를 들어 Member entity와 Team entity가 있다고 가정해보자. Team 에는 여러명의 Member가 소속될 수 있다면, Member와 Team Entity는 N : 1 관계가 된다. 기본적으로 @M..