2016-12-23 16 views
0

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 

答えて

1

必要があります。

@Query("select t from Telemetry t where t.id = :id and t.updateTimestamp between :startTime and :endTime and :#{T(java.lang.Math).random()} < :samplingRate ") 

あなたのPOM

<dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-jpa</artifactId> 
     <version>1.10.5.RELEASE</version> 
    </dependency> 
+0

どちらも仕事をバンプするのに役立ちます。次のアイデア。私は質問を更新しました –

+0

私はあなたにアップフォートを渡しましたが、私自身の答えを見つけました。バンプも必要です –

0

Answer使用しない場合は、この:#

select t from Telemetry t where t.id = :id and t.updateTimestamp between :startTime and :endTime and :#{T(java.lang.Math).random()} < :samplingRate 

のように試みることができる乱数

+0

ええ、私はそれを働かせました..今度はランダムに結果をsamplingFactorに渡します: - /新しい質問 –