Is it possible to write an HQL query with case-insensitive 'where' criteria? i.e.:
Code:
class User{
private String name;
public String getName(){
return this.name;
}
}
Let's say I am trying to find all Users with name 'Joe', but I do not care about case (i.e. I'd like to match "JOE" and "joe"):
Code:
User u = new User();
u.setName("Joe");
String hqlQuery = "from User as usr where usr.name = "+u.getName();
//the above query will return users with 'name' "Joe" only, but not "joe" or "JOE" etc.
I'd like 'where' comparison to be case-insensitive. How would you rewrite the above query to achieve that?
Would the following work?:
Code:
String hqlQuery = "from User as usr where lower(usr.name) = "+u.getName().toLowerCase();
I realize that this can be achieved by using Criteria class, but in my current application, I have to use HQL.
Thanks,
-nikita
Hibernate version:
3.1
Name and version of the database you are using:
MySQL 4.1 (InnoDB)