QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list ( DTO에 fetchJoin 사용 이슈)

2022. 8. 30. 13:46·개발/이슈
728x90

1. 이슈

  • QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list 오류
return queryFactory.select(new QMemberTeamDto( 
                                member.id.as("memberId"),
                                member.username,
                                member.age,
                                team.id.as("teamId"),
                                team.name.as("teamName")
						))
                    .from(member)
                    .leftJoin(member.team,team).fetchJoin()
                    .where(builder)
                    .fetch();

2. 원인

  • DTO 반환 형식에 fetchJoin을 사용하여 발생하였습니다.

2-1. fetch join을 사용하는 이유

  • 엔티티 상태에서 엔티티 그래프를 참조하기 위해 사용합니다. (N+1) 해결
  • 엔티티가 아닌 DTO 상태로 조회하는 것은 불가능
  1. 해결
  • 반환형식이 DTO 일 때는 fetchJoin() 빼면 됩니다.
728x90

'개발 > 이슈' 카테고리의 다른 글

[Spring Data JPA] No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call 에러 해결 (db 저장 시 Transactional 미입력 이슈)  (0) 2022.08.30
jpa json 순환 참조 이슈  (0) 2022.08.30
'개발/이슈' 카테고리의 다른 글
  • [Spring Data JPA] No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call 에러 해결 (db 저장 시 Transactional 미입력 이슈)
  • jpa json 순환 참조 이슈
nix-be
nix-be
  • nix-be
    NiX
    nix-be
  • 전체
    오늘
    어제
    • 홈
      • 책
        • 오브젝트
      • 성장
        • jpa Querydsl 정리
        • 코딩테스트
      • 인프라
        • linux
        • vmware
        • CI&CD
        • 네트워크
        • docker
      • 개발
        • spring boot
        • JPA
        • java
        • thymeleaf
        • 이슈
        • jquery
        • javascript
        • 안드로이드
      • DB
        • postgreSql
      • 잡다한것
        • 프로그램
        • 일상 관련
      • 회사
        • 티
  • 블로그 메뉴

    • 홈
    • 개발
  • 링크

  • 공지사항

  • 인기 글

  • 태그

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
nix-be
QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list ( DTO에 fetchJoin 사용 이슈)
상단으로

티스토리툴바