You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
다음과 같이 travel에 속한 user들의 정보와 travel의 정보를 모두 불러올 수 있도록 fetch join을 이용해 jpql 쿼리를 만들어 사용할 수 있다.
@Query("select distinct t from Travel t join fetch t.userTravels ut join fetch ut.user where t.id = :travelId")
Optional<Travel> findTravelById(Long travelId);
그러나 이럴 경우 테스트에서 RecordNotFoundException이 간혹 발생함을 확인할 수 있었다. (해당 exception이 항상 발생하지 않는 점이 원인 파악의 힌트가 되었다.) 이는 fetch join이 쿼리 레벨에서 inner join의 형태로 작동해 travel과 연관된 userTravel이 없을 경우 아무런 레코드를 반환해주지 않는 것이 원인이었다.
따라서 다음과 같이 left outer join을 이용한 fetch join을 이용함으로써 해결할 수 있었다.
@Query("select distinct t from Travel t left join fetch t.userTravels ut left join fetch ut.user where t.id = :travelId")
Optional<Travel> findTravelById(Long travelId);
The text was updated successfully, but these errors were encountered:
다음과 같이 travel에 속한 user들의 정보와 travel의 정보를 모두 불러올 수 있도록 fetch join을 이용해 jpql 쿼리를 만들어 사용할 수 있다.
그러나 이럴 경우 테스트에서 RecordNotFoundException이 간혹 발생함을 확인할 수 있었다. (해당 exception이 항상 발생하지 않는 점이 원인 파악의 힌트가 되었다.) 이는 fetch join이 쿼리 레벨에서 inner join의 형태로 작동해 travel과 연관된 userTravel이 없을 경우 아무런 레코드를 반환해주지 않는 것이 원인이었다.
따라서 다음과 같이 left outer join을 이용한 fetch join을 이용함으로써 해결할 수 있었다.
The text was updated successfully, but these errors were encountered: