JPA

JPQL작성 (native Query) No converter found capable of converting from type 에러해결하기

dev.mk 2023. 12. 17. 15:03
반응형

JPA프로젝트에서 통계쿼리를 JPQL로 작성하고 리턴하다 발생한 에러인데 해결방법을 공유한다.

 

오류 내용

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

 

JPQL로 작성한거라 Entity도 따로 만들수가 없었다. 일반적인 dto Class로 리턴하려다가 에러가 발생.

 

결론적으로 Interface로 리턴해야한다.

public interface JqplResponse {
    long getMember_rank(); //순위
    long getCount(); //건수
}

 

엔티티처럼 카멜케이스를 자동으로 바꿔주지 않기 때문

JPQL에서 컬럼명을 바꿔주던지, 컬럼 원래 이름으로 사용해야한다.

    @Query(value =
        "SELECT"+
        " tt.member_rank as member_rank"+
        " tt.count as count"+
        " FROM tbl_test tt"+
        " INNER JOIN test AS t"+
        " ON t.no = tt.no"+
         , nativeQuery = true
    )
    List<JpqlResponse> totalListWithJPQL();
반응형