我正在尝试这样做:
@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]
最佳答案
如果您再次想要隔离 comarca_id 列表,请尝试流式传输您的请求结果。
List<Comarca> comarca = debitoNegativacao.stream().map(dn -> dn.getComarca()).distinct().collect(Collectors.toList());
++
关于java - 如何使用外键类型从 jpa 存储库返回选择查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54255858/