Q:

Case-insensitive equals using Hibernate Criteria

I've seen Restrictions.ilike('property', '%value%'), but would like to generate SQL like:  lower(property) = 'value'.  Any ideas?
I used:  
Restrictions.eq("email", email).ignoreCase()

since Expression is deprecated.  The SimpleExpression will call toLowerCase() on the value, so it is not necessary to do it beforehand.
See:  SimpleExpression source

A:

Expression is now deprecated. Use Restrictions instead ...
crit(Restrictions.eq("firstName", firstName).ignoreCase());

A:

Be careful of using ilike because it would allow someone to enter things like "test%" and match.  I use the following to do a case-insensitive equal in one app:
...
Criteria crit=session.createCriteria(Event.class);
crit.add(Expression.eq("rsvpCode","test1").ignoreCase());
...

A:

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.

