This Question refers to Spring Data JPA.
I need a (native) @Query with the Lower Function and Wildcards. But I dont get it to work.
Here is a oversimplified version of what I am looking for:
@Query(value = "SELECT * FROM CAR c WHERE LOWER(c.model) LIKE LOWER(%:model%)", nativeQuery = true)
List<Car> findByModelMatching( @Param("model") String model );
LOWER(%:model%) -> not working! LOWER(:model) -> works!
I am aware of that such a query can be easily re-written as:
List<Car> findByModelContainingIgnoreCase( String model );
But I am not looking for a Named Query.
My Question is: How to combine LOWER (or even UPPER) with WildCards in a @Query!
Cheers
The LOWER
function accepts strings, you should write LOWER('%' || :model || '%')
if you are on Oracle for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With