0

I want to use named parameters in native query. It works fine in cases like this:

and p.department_id in :myDepthsIds 
...
query.setParameter("myDepthsIds", myDepthsIds);

However, I want to use named parameter in "LIKE" part of query, and if I try

stringQuery = stringQuery + " and upper(p.name) like upper('%:searchString%')";
...
query.setParameter("searchString", searchString);

it gives me

java.lang.IllegalArgumentException: Unknown parameter name : searchString

So, what is a right way to use named parameters in "LIKE", "LIKE UPPER" etc?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
MichaelSun
  • 90
  • 1
  • 9
  • Problem is solved by help of this post https://stackoverflow.com/questions/21456494/spring-jpa-query-with-like – MichaelSun Aug 12 '21 at 20:52
  • When you use `'%:searchString%'`, that means a literal string with the string value `%:searchString%`. What you want would be `'%' || :searchString || '%'` (assuming standard SQL syntax) – Mark Rotteveel Aug 13 '21 at 09:57

0 Answers0