I\'ve seen Restrictions.ilike(\'property\', \'%value%\'), but would like to generate SQL like: lower(property) = \'value\'. Any ideas?
I used:
Restri
As Andy's answer suggests, this for case-insensitive searches but it is also works through to Hibernate version 4.1:
crit(Restrictions.eq("firstName", firstName).ignoreCase());
Versions 4.1.1 and later of Hibernate do not support the ignoreCase()
method on Restriction.eq()
. For that, we have to use ilike
with MatchMode
.
Criteria crit = session.createCriteria(ENTITY.class);
crit.add(Restrictions.ilike('PROPERTY NAME', 'VALUE', MatchMode.ANYWHERE));
As an example, for a USER entity with id, name, surname properties, a case-insensitive search based on name will be:
Criteria crit = session.createCriteria(USER.class);
crit.add(Restrictions.ilike('name', 'Satyam', MatchMode.ANYWHERE));
This will return all results, case insensitive.