2016-05-18 9 views
0

は、ここに私のネイティブクエリである「その位置でのパラメータは、[1]は存在しませんでした」HQLクエリー

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 

は、だから私はこれまで何をしたか:=

  1. は、引数の順序(まだ同じエラー)に変更
  2. は、サブクエリが含まれるようにクエリを変更しましたが、残念ながらHQLは 制限
  3. が日付を変更サポートしていません。 :date part to date =?2(まだ同じエラーです)

私を助けてくれますか?

答えて

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);