当前位置: 首页 > 知识库问答 >
问题:

如何解决找不到能够从tuplebakedmap类型转换为[com.example.dto.exampledto]类型的转换器

顾琛
2023-03-14
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]

当我在本机JPA查询中使用返回2个值的查询时,就会抛出上述错误。我在下面的DTO中捕获查询响应:

@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ExampleDto {
    @Id
    private String name1;
    private int nameFlag;
}
List<ExampleDto> getExampleDto = myJPARepository.
                .findNameObject(uuid);
@Query(value = "select name1, nameFlag from NameTable",
          nativeQuery = true, name = "findNameObject where namekey = ?")
    List<ExampleDto> findNameObject(
            @Param("nameKey") UUID nameKey);

共有1个答案

闾丘书
2023-03-14

这是一个bug:https://jira.spring.io/browse/datajpa-1714

您可以将JPQL与构造函数表达式、接口投影或自定义方法实现一起作为解决方案。

 类似资料: