Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignorecase for In-Criterion

i'd like to select items case insensitive with an In-Criterion with Hibernate Criteria API. E.g.

Criteria crit = session.createCriteria(Item.class);
crit.add(Restrictions.in("prop", valueList).ignoreCase());

Unfortunately the Criterion class doesn't has an ignoreCase method. HQL is not an alternative.

like image 317
Cengiz Avatar asked Dec 16 '22 21:12

Cengiz


1 Answers

Get the source code of the Criterion class returned by Restrictions.in() (InExpression), and create another one which is similar but transforms all the elements of the value list to lowercase, and generates a SQL query like:

lower(prop) in (...)
like image 193
JB Nizet Avatar answered Dec 28 '22 11:12

JB Nizet