我想在spring-data中使用sql select by method name。
选择应按价格排序。
@Entity
public class Product {
int name;
BigDecimal price;
}
interface ProductRepository extends CrudRepository<Product, Long> {
Product findFirstByNameOrderByPriceAsc(String name);
}
结果:
org.springframework.dao.IncorrectResultSizeDataAccessException: result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements
为什么?出于这个原因,我完全使用了 findFirst()
方法,以便在找到多个结果时获得最佳结果..
最佳答案
Top
和 First
关键字自 spring-data-jpa-1.7.1.RELEASE
起可用。见 Spring Data JPA Changelog和 Limiting query results
关于java - Spring-data findFirstBy 抛出 IncorrectResultSizeDataAccessException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27400711/