[SpringBoot] JPA 오류: No converter found capable of converting from type - 2
JPA native query에서 DTO로 매핑할 때 호환이 잘 안 되면 이런 문제가 발생한다.
그래서 구글링한 결과 Interface로 받아야 한다고 해서, JPA -> Interface -> DTO -> Service 로 받아서 사용하였다.
근데 그냥 Interface만 사용해도 괜찮을 것 같아서 수정했다.
사실 위에처럼 DTO, Interface 두 개의 파일이 있는 게 너무 불편했다..
이전에 시도했던 방법
https://kongjino.tistory.com/25
[SpringBoo] JPA 오류: No converter found capable of converting from type
Native Query로 Join 후 두 테이블 이상 select 할 때, entity를 DTO로 매핑하지 못해 발생하는 문제 해결 방법입니다. JPA로 SELECT a, b FROM A a, B b WHER a.id = b.id; 같은 쿼리를 보내고, DTO로 받고 싶을 때 문제가
kongjino.tistory.com
MyRepository.java
@Query(value = "SELECT ... "FROM ..., ... WHERE ...")
List<MyInterface> findAll();
MyInterface.java
public interface MyInterface {
Long getId();
String getName();
}
MyService.java
@Transactional(readOnly = true)
public List<MyInterface> findAll() {
return myRepository.findAll();
}
native query를 안 쓰고 JPA 함수로만으로도 처리할 수 있는 방법이 있다는데...(JPA에서 DTO로 받을 수가 있음)
아직은 솔직히 쿼리 작성이 직관적인 것 같아 이걸로 사용할 예정이다!
참고한 블로그
https://coding-log.tistory.com/248
[Spring Data JPA] org.springframework.core.convert.ConverterNotFoundException No converter found capable of converting from type
프로젝트를 진행하다가 이런 에러가 발생했다. org.springframework.core.convert.ConverterNotFoundException No converter found capable of converting from type 원인은 JPA를 활용해서 nativeQuery로 쿼리를 돌린걸 DTO에 맵핑하
coding-log.tistory.com