개발/이슈3 QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list ( DTO에 fetchJoin 사용 이슈) 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을 사용하여 발.. 2022. 8. 30. [Spring Data JPA] No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call 에러 해결 (db 저장 시 Transactional 미입력 이슈) 1. 이슈 내용 현재 스레드에 EntityManager가 없다고 persist 할 수 없습니다. 2. 원인 em.flush 하는데 transactional 어노테이션을 입력을 안 했습니다. 3. 해결 방법 해당 함수에 @Transactional 입력 @Transactional public Page findAllSort(Pageable pageable) { QMember member = QMember.member; QBoard board = QBoard.board; em.flush(); em.clear(); List content = queryFactory.select(member) .from(member) .join(member.boards , board).fetchJoin() .where(member... 2022. 8. 30. jpa json 순환 참조 이슈 1.이슈 상태 매핑된 데이터 FetchType.LAZY 사용 두 Entity가 1:N ,N : 1 양방향 관계 Entity를 json으로 직렬화하여 반환할 경우 순환 참조 발생 Entity 에 @Data , @ToString, @EqualsAndHashCode 을 사용하면서 두 객체가 서로의 필드를 계속 참조하면서 순환참조 발생 @ResponseBody 사용 시 객체 직렬화 2. 원인 jpa에서 양방향으로 연결된 Json을 직렬화하는 과정에서 서로 정보를 순환 참조하여 문제 발생 3. 해결 방법 3-1. Dto로 반환하여 해결 가장 추천하는 방식 3-2. @JsonManagedReference, @JsonBackReference 사용하여 순환 참조를 해결 @JsonBackReference 연관관계의 주인.. 2022. 8. 30. 이전 1 다음