Sunday, June 14, 2009

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.

No comments:

 
Software