如何解决没有找到能够从TupleBackedMap类型转换为[com.example.dto.ExampleDto]类型的转换器

问题描述 投票:0回答:1
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;
}

并且在DAO类中,我正在按以下方式调用本机查询。该查询在SQL Developer中有效,并返回2条记录。但是,当按如下方式调用时,会引发上述错误。

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

DTO类中有什么问题,我需要更改。注释?我不确定这里缺少什么,请尝试使用@Entity注释,@ Data注释,尝试调用查询时无法解决此错误。

更新:与此相关的本机查询是

@Query(value = "select name1, nameFlag from NameTable",
          nativeQuery = true, name = "findNameObject where namekey = ?")
    List<ExampleDto> findNameObject(
            @Param("nameKey") UUID nameKey);
spring-boot jpa nhibernate spring-data-jpa nativequery
1个回答
1
投票
© www.soinside.com 2019 - 2024. All rights reserved.