how to use ignore case in spring JPA @query?

4.3k Views Asked by At

I have query as below:

@Query("SELECT b FROM Brand b WHERE b.name1 LIKE %:name1% or b.name2 like %:name2%")
List<Brand> findSome(@Param("name1") String name1, @Param("name2") String name2);

I want to ignore case so that I tried to modified it

@Query("SELECT b FROM Brand b WHERE lower(b.name1) LIKE lower(%:name1%) or lower(b.name2) like lower(%:name2%)")

But this looks like don't work, how can I do?

1

There are 1 best solutions below

1
On BEST ANSWER

The problem is probably the syntax of your JP-Query. Try to use this:

lower(b.name1) LIKE concat('%', lower(:name1), '%')

Further reference: http://openjpa.apache.org/builds/1.2.3/apache-openjpa/docs/jpa_langref.html#jpa_langref_like