Spring-data findFirstBy throwsestResultSizeDataAccessException?
我想在弹簧数据中使用sql按方法名称选择。
选择应按价格排序。
@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()