【发布时间】:2014-10-16 18:06:16
【问题描述】:
我有一个名为“ImportReceiptRepository”的 Spring CrudRepository。
我只是想编写一个方法来获取 order by 子句中的第一行。
这是我目前正在使用的:
ImportReceipt importReceipt = this.importReceiptRepository.getOneByImportTypeOrderByTimestampDesc(importType);
问题是当返回多于一行时,Spring 会抛出:
org.springframework.dao.IncorrectResultSizeDataAccessException: result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements
当返回 0-n 行时,我应该如何重命名这个 CrudRepository 函数以简单地抓取第一行?
【问题讨论】:
标签: java sql spring spring-data