这是我的原生查询(遗憾的是我不能使用它,因为本机查询不适用于可分页)
select * from stock_indicators si inner join stock st on si.stock_id = st.id where si.slope_simple_regression_10 > 1 and si.date = (select date from stock_details order by date desc limit 1) order by si.slope_simple_regression_10 desc
这是一个相应的hql查询:
@Query(value = "from StockIndicators si join fetch si.stock where si.slopeSimpleRegression10Days > 1 and si.date = :date order by si.slopeSimpleRegression10Days desc", countQuery = "select count(si.stock) from StockIndicators si where si.slopeSimpleRegression10Days > 1")
Page<StockIndicators> findWithStocksIndicators10DaysTrendUp(Pageable pageable, @Param("date") LocalDate date);
此查询不起作用,发生以下错误:
java.lang.IllegalArgumentException: Parameter with that position [1] did not exist
所以我到目前为止做了什么:
你能帮帮我吗?
答案 0 :(得分:0)
最后我找到了解决方案。这是我的愚蠢错误。我忘了给countQuery添加参数。正确的方法应该是:
@Query(value = "from StockIndicators si join fetch si.stock where si.slopeSimpleRegression10Days > 1 and si.date = :date order by si.slopeSimpleRegression10Days desc", countQuery = "select count(si.stock) from StockIndicators si where si.slopeSimpleRegression10Days > 1 and si.date = :date ")
Page<StockIndicators> findWithStocksIndicators10DaysTrendUp(Pageable pageable, @Param("date") LocalDate date);