Logs

[Spring Data JPA] org.springframework.core.convert.ConverterNotFoundException No converter found capable of converting from type 에러 해결 방법

랩실외톨이 2023. 4. 12. 18:24
반응형

프로젝트를 진행하다가 이런 에러가 발생했다.

 

org.springframework.core.convert.ConverterNotFoundException
No converter found capable of converting from type

 

원인은 JPA를 활용해서 nativeQuery로 쿼리를 돌린걸 DTO에 맵핑하는 과정에서 서로 호환이 안 돼서 생긴 문제이다.

JPA에서 DB에 필요한 속성만을 조회하는 것을 Projection이라고 한다. Projection은 엔티티 기반이 있고 DTO 기반이 있는데 나는 JPA에서 DTO 형식으로 조회했기 때문에 interface 기반의 projection을 사용해야 이 문제를 해결할 수 있었다.

 

그래서 DTO를 class에서 interface로 수정했다. 조회를 원하는 속성들의 집합으로 get(필드명) 형식으로 코드를 작성하면 호환이 가능하다.

 

 

ex)

 

원래 코드 class

 

@Getter
public class ADto {
    private String A;
    private String B;
}

 

수정된 코드 interface

 

public interface ADto {
    String getA();
    String getB();
}

 

 

반응형