title: spring JPA query with spel expression for random
body: <p>I am trying to generate a random number so I can do sampling in a data set in a JPA query. I have read this is totally possible everywhere but I keep getting errors:</p>
  
  <p>code:</p>
  
  <pre><code>@Query("select t from Telemetry t where t.id = :id and t.updateTimestamp between :startTime and :endTime and #{ #T(java.lang.Math).random() } &lt; :samplingRate ")
  Iterable&lt;Telemetry&gt; findFor(@Param("id") String org, @Param("startTime") Instant startTime, @Param("endTime") Instant endTime, @Param("samplingRate") Float samplingRate);
  </code></pre>
  
  <p>error:</p>
  
  <blockquote>
    <p>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() } &lt;
    :samplingRate ]</p>
  </blockquote>
  
  <p>Digging deeper into this I discover this exception:</p>
  
  <pre><code>throw new IllegalArgumentException("Parameter with that position [" + parameterPosition + "] did not exist");
  </code></pre>
  
  <p>parameter position is 1 or 2 Depending on which syntax I use.</p>
  
  <p>I have tried with with/without hashes. No luck. I am using postgres which has a <code>random()</code> function but it doesn't like me invoking that either (which is my ultimate goal). </p>
  
  <p>This question is about using SPeL, but I just need a random number</p>