Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine JPA Query annotation with Oracle sample method

i am trying to pass a parameter into a JPA query
Example code

 @Query(value =
              "select *\n"
            + "from adress sample(:percentile)\n"
            + "where adress.number in (:adressNumbers)\n"
            + "fetch first (:rows) rows only,"
            + "nativeQuery = true
           List<X> sampleExample(Integer rows, List<Integer> adressNumbers, Double percentile)

But i get an error because of the sample(:percentile).
If i just hardcode a number in there it works but not with a param.
Is there a way to escape the brackets or something similar?
Thx

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The error is on the following part

from adress sample(:percentile)

Unfortunately it does not belong to the where part of the query and so the parameter passed :percentile can’t be bound to the query.

There is not any quick fix around this. You won’t be able to use a method parameter that will be able to be bound in the query in the part that you want it to be, because parameters can only be bound in the where part of the query.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading