LAZY로딩 EAGER처럼 사용하기

김지원·2023년 11월 23일
0

리포지토리

	// @OneToMany에 LAZY일 때, 객체를 호출할 때마다 select 쿼리 날라감
    List<Aquarium> findByUserId(int userId);

    // LAZY인데 EAGER처럼 fishList를 처음부터 가져오게
    @EntityGraph(attributePaths = "fishList")
    @Query("SELECT a FROM Aquarium a WHERE a.user.id = :userId")
    List<Aquarium> findByUserIdEagerFishList(@Param("userId") int userId);
    

@EntityGraph

profile
https://github.com/k7850

0개의 댓글

관련 채용 정보