Hibernate + Postgresql with case insensitive searching Hibernate + Postgresql with case insensitive searching postgresql postgresql

Hibernate + Postgresql with case insensitive searching


In SQL I've played the trick before, which I believe is SQL compliant in most RDBMS's:

SELECT * FROM UPPER(bar) = 'HELLO WORLD'

You can capitalize before you pass the parameter in. This would probably be the same as using the Restrictions.ilike() criteria for a query in Hibernate.


Spring can be handy in configuring things like how you connect hibernate and postgres together, transaction (if needed), and how you obtain A HibernateSession object. In fact using spring you can use HibernateTemplates (a Spring object) that will proxy a lot of stuff for you.

However, you still have program-ability around what queries you run. In this case using a HibernateTemplate you could write:

String parameter = "hello wOrlD"DetachedCriteria criteria = DetachedCriteria.forClass(objectClass)                             .add(Restrictions.ilike("name", parameter)));List<Object> result = template.findByCriteria(criteria);

or you could look into using Restrictions.eq or sqlRestriction to implement the sql piece of it.


There is not a way to just simply tell Postgres to ignore case.

If changing the type of all the columns where you need this comparison is an option, then look at the citext datatype.