我想在spring-data中使用sql select by method name。
select应按价格排序。
@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()方法,以便在找到多个结果时获得最高结果。
发布于 2014-12-10 22:28:19
Top和First关键字从spring-data-jpa-1.7.1.RELEASE开始可用。请参阅Spring Data JPA Changelog和Limiting query results
https://stackoverflow.com/questions/27400711
复制相似问题