首页 > 解决方案 > 如何使用外键类型从 jpa 存储库返回选择查询

问题描述

我正在尝试这样做:

@Query(value = "SELECT DISTINCT c.* FROM comarca c INNER JOIN debito_negativacao d ON d.comarca_id = c.id WHERE d.status = :status", nativeQuery = true)
List<Comarca> findDistinctComarcaByStatus(@Param("status") String status);

但我得到这个错误:

  org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.Object[]] to type [com.hc.projects.model.Comarca] for value '{9, 0, 7323}'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.math.BigInteger] to type [com.hc.projects.model.Comarca]

标签: javaspringhibernatespring-data-jpa

解决方案


您的请求告诉您想要一个 BigInteger 列表: SELECT DISTINCT comarca_id... 因为我猜comarca_id 是一个 biginteger。如果你想要一份 Comarca 名单,你必须在你的所有桌子上提出​​要求。


推荐阅读