JPAクエリのデータセットでサンプリングを行うために乱数を生成しようとしています。私は、これはどこにでも完全に可能である読んだが、私はエラーを得続ける:spel式のランダムJPAクエリ
throw new IllegalArgumentException("Parameter with that position [" + parameterPosition + "] did not exist");
:私はこの例外を発見し、この深く掘り
org.hibernate.QueryException: unexpected char: '#' [select t from com.mz.rad.dao.Telemetry t where t.id = :id and t.updateTimestamp between :startTime and :endTime and #{ #T(java.lang.Math).random() } < :samplingRate ]
:
コード:
@Query("select t from Telemetry t where t.id = :id and t.updateTimestamp between :startTime and :endTime and #{ #T(java.lang.Math).random() } < :samplingRate ")
Iterable<Telemetry> findFor(@Param("id") String org, @Param("startTime") Instant startTime, @Param("endTime") Instant endTime, @Param("samplingRate") Float samplingRate);
がエラーを
パラメータの位置は1または2です。使用する構文に応じて、
ハッシュなしで試しました。運がない。私はrandom()
機能を持っているpostgresを使用していますが、それはどちらかを呼び出すのが好きではありません(これは私の最終目標です)。
この質問はSPELの使用についてですが、私はちょうどその?#
select t from Telemetry t where t.id = :id and t.updateTimestamp between :startTime and :endTime and ?#{T(java.lang.Math).random()} < :samplingRate
どちらも仕事をバンプするのに役立ちます。次のアイデア。私は質問を更新しました –
私はあなたにアップフォートを渡しましたが、私自身の答えを見つけました。バンプも必要です –