Spring-data findFirstBy抛出IncorrectResultSizeDataAccessException?

mem*_*und 13 java spring

我想在spring-data中使用方法名称的sql select.

选择应按价格排序.

@Entity
public class Product {
    int name;
    BigDecimal price;
}

interface ProductRepository extends CrudRepository<Product, Long> {
    Product findFirstByNameOrderByPriceAsc(String name);
}
Run Code Online (Sandbox Code Playgroud)

结果:

org.springframework.dao.IncorrectResultSizeDataAccessException: result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements
Run Code Online (Sandbox Code Playgroud)

为什么?我正是findFirst()因为这个原因才使用该方法才能获得最佳结果,如果找到多个...

Tka*_*gen 19

TopFirst关键字可用spring-data-jpa-1.7.1.RELEASE.请参阅Spring Data JPA ChangelogLimiting查询结果