tags:

views:

2831

answers:

2

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

+1  A: 

I'm not absolutely sure, but when you use Restriction.eq you obtain a SimpleExpression object, and that object suppports an ignoreCase() operation which I've never tried using but sounds like it could make a difference.

Kudos to Hibernate for not documenting what this method actually does.

Uri
Careful Uri, Gavin King or Christian Baer might be watching... 8) They tend to be a little defensive about criticism on the Hibernate forums.
duffymo
I've doing my Ph.D. research on the usability and correctness of JavaDocs... So completely omitting the JavaDocs on that methods takes away from my work ;)
Uri
+7  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());
...
John Wagenleitner