Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve No converter found capable of converting from type TupleBackedMap to type [com.example.dto.ExampleDto]

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.example.dto.ExampleDto]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:174) ~[spring-core-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.data.repository.query.ResultProcessor$ProjectingConverter.convert(ResultProcessor.java:293) ~[spring-data-commons-2.1.5.RELEASE.jar:2.1.5.RELEASE]

The above error is being thrown when I have a query that returns 2 values in a native JPA query is being used. I'm capturing the query response in the DTO below:

@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ExampleDto {
    @Id
    private String name1;
    private int nameFlag;
}

And in a DAO class, I'm calling the native query as below. The query works in SQL Developer and returns 2 records. But when called as below , it throws the above error.

List<ExampleDto> getExampleDto = myJPARepository.
                .findNameObject(uuid);

There is something wrong in the DTO class, which i need to change. Annotations? I'm not sure what is missing here, and try as I might , putting in @Entity annotation, @Data annotation , I'm not able to resolve this error when the query is called.

UPDATE: The native query associated with this is

@Query(value = "select name1, nameFlag from NameTable",
          nativeQuery = true, name = "findNameObject where namekey = ?")
    List<ExampleDto> findNameObject(
            @Param("nameKey") UUID nameKey);
like image 246
Ronald Avatar asked Jan 26 '23 04:01

Ronald


1 Answers

This is a bug: https://jira.spring.io/browse/DATAJPA-1714

You can either use JPQL with a constructor expression, an interface projection or a custom method implementation as a workaround.

like image 96
Jens Schauder Avatar answered Jan 29 '23 14:01

Jens Schauder