org.springframework.core.convert.ConverterNotFoundException i spring-data jpa

问题描述 投票:0回答:1

我有这样的疑问:

@Query(value = "SELECT t1.* FROM western_en AS t1 " +
        "JOIN (SELECT id FROM western_en " +
        "ORDER BY RAND() LIMIT 10) as t2 ON t1.id=t2.id", nativeQuery = true)
List<WesternEs> findRandom();

但是我运行查询时遇到此错误:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [com.models.WesternEs]
    at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:294)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:185)
    at org.springframework.core.convert.support.ArrayToObjectConverter.convert(ArrayToObjectConverter.java:68)
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
java mysql spring spring-boot spring-data-jpa
1个回答
0
投票

您是否尝试过在 SQL 控制台上查看查询返回什么?

尝试后,查看查询输出的数据是否与

WesternEs
实体字段相同(以及数据的类型是否可以“相同”)。

但这看起来列

id
作为 Long 返回,而
WesternEs
实体
id
可能不是
Long
??

如果此后您无法解决问题,您能否提供有关

WesternEs
实体的更多信息?

© www.soinside.com 2019 - 2024. All rights reserved.