Case insensitive search in hibernate

It is very simple to do case insensitive search in hibernate.
Here is an example HQL query:

Query q = this.entityManager.createQuery("SELECT * FROM User u where lower(u.firstName)=:firstName");
q.setParameter("firstName", firstName.toLowerCase());

In this case lower() will convert the firstName property to lower case allowing you to do case insensitive search.

2 thoughts on “Case insensitive search in hibernate”

Leave a Reply

Your email address will not be published. Required fields are marked *