我有一个表,在那里我需要根据两列获取行,并在一列的帮助下找到顶级记录。
---------------------------------------------------------------------
id product_id sub_product_id created_dttm
---------------------------------------------------------------------
1 1 2 01-02-2021 07:03:25
2 2 1 01-01-2021 08:03:25
3 1 2 01-02-2021 09:03:25
4 2 1 01-02-2021 08:03:25
在上面的表中,我必须获得productid
和subproductid
之间的行,按created_dttm
排序,以获得最后插入的记录。
在春季jpa我正在尝试派生查询如下
public List<DailyStock> findTopByProductIdAndSubProductIdOrderByCreatedDttmDesc();
我想要行id 3 &4作为list返回
在执行上面的查询时,我得到错误
expects at least 1 arguments but only found 0. This leaves an operator of type SIMPLE_PROPERTY for property productTypeId unbound.
你应该给你的方法添加参数
public List<DailyStock> findTopByProductIdAndSubProductIdOrderByCreatedDttmDesc(
Long productId,
Long subProductId
);
我假设这两列都映射到DailyStock
类的Long
属性
更新:如果您不想传递任何参数,您应该重命名您的方法以从过滤查询中排除列:
public List<DailyStock> findTopByOrderByCreatedDttmDesc();