如何解决未找到能够从TupleBackedMap类型转换为[com.example.dto.ExampleDto]类型的转换器 [英] How to resolve No converter found capable of converting from type TupleBackedMap to type [com.example.dto.ExampleDto]

查看:99
本文介绍了如何解决未找到能够从TupleBackedMap类型转换为[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]

当我有一个使用本地JPA查询返回2个值的查询时,抛出上述错误.我正在下面的DTO中捕获查询响应:

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;
}

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

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);

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

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);

推荐答案

这是一个错误: https://jira.spring.io/browse/DATAJPA-1714

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

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

这篇关于如何解决未找到能够从TupleBackedMap类型转换为[com.example.dto.ExampleDto]类型的转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆