Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiberate : HQL Case Insensitive search

My requirement is to do a search in database based on a string.

That particular string might be stored in uppercase, in database.

So, I will have to do a case-insensitive search through HQL

My current HQL is

String query = "from OrganizationContent where orgUrl=:url";
        Map<String,Object> parameterMap = new HashMap<String,Object>();
        parameterMap.put("url", organizationUrlInput.toLowerCase());

Only ".toLowerCase" I can do from java end. Now I need hibernate to fetch the data by doing a case-insensitive search.

Appreciate your help on this friends

like image 588
Arun Avatar asked Dec 17 '22 03:12

Arun


1 Answers

From the documentation:

Expressions used in the where clause include the following:

[...]

Any function or operator defined by EJB-QL 3.0: substring(), trim(), lower(), upper(), length(), locate(), abs(), sqrt(), bit_length(), mod()

from OrganizationContent where lower(orgUrl) = :url
like image 174
JB Nizet Avatar answered Jan 09 '23 11:01

JB Nizet