我想在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()因为这个原因才使用该方法才能获得最佳结果,如果找到多个...
| 归档时间: |
|
| 查看次数: |
16850 次 |
| 最近记录: |