n+1

    JPA N + 1, FetchJoin, EntityGraph

    JPA N + 1, FetchJoin, EntityGraph

    필자는 Spring Data JPA 를 많이 사용 중에 있다. 초반에 해당 문제로 골머리를 앓았던 기억이 있는데 그때 기억도 나는 겸 다시 정리도 하는 겸하여 정리해보고자 한다. 준비 우선 테스트를 진행해 볼 엔티티를 작성하자. 책과 작가를 엔티티로 삼았으며 책 → 작가를 의존하는 ManyToOne 관계를 맺어주었다. 코드는 아래와 같다. Entity @Entity @Getter @NoArgsConstructor @ToString public class Book { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String title; @ManyToOne private Author author; public..