웹 개발 공부 : Back-end/JPA

[JPA 프로젝트 회고 - 7] org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type ~ 에러 해결

Developer KTU 2024. 10. 11. 18:24
반응형

1. 개요

게시판 조회 쿼리(네이티브 쿼리)를 작성하고 여러 ROW 건수를 DTO를 활용하여 리턴할 때 마주한 에러이다. 이 에러를 해결한 사례를 포스팅한다.

 

2. 원인

쿼리 조회 결과와 DTO 간의 매핑이 제대로 되지 않아 생긴 오류이다.

 

3. 해결방법

네이티브 쿼리를 사용하고, 다중 건수의 DTO로 리턴하기 위해선 DTO를 class로 만들지 않고, interface로 생성한다.

// as-is
@Data
@NoArgsConstructor
public class MyDto {

    private String A;
    private String B;
    
    // ...
    
}
// to-be
public interface MyDto {

    String getA();
    String getB();
    
    // ...
    
}
반응형