I am implementing an autocomplete functionality using Jquery, when I type the name, it fetches the record from the db, The records stored in db are mixture of capital & small letters. I have written a HQL Query which fetches me the records with case-sensitive, but I need to records irrespective of case. Here is the query,
List<OrganizationTB> resultList = null; Query query = session.createQuery("from DataOrganization dataOrg where dataOrg.poolName like '%"+ poolName +"%'"); resultList = query.list();
Ex : If I have pool names, HRMS Data set, Hrms Data, Hr data etc... if I type HR or hr I need to get all the 3 records, which I'm not able to.
Please help...
HQL queries are case insensitive; however, the names of Java classes and properties are case-sensitive HQL is used to execute queries against database.
ilike(), which does a case-insensitive search. Just beware if you're switching from Eq to Like, you'll also get wildcards enabled, so things like underscores in oracle matching any character.
14.1.Queries are case-insensitive, except for names of Java classes and properties. So SeLeCT is the same as sELEct is the same as SELECT but org. hibernate.
The Hibernate Query Language (HQL) and Java Persistence Query Language (JPQL) are both object model focused query languages similar in nature to SQL. JPQL is a heavily-inspired-by subset of HQL. A JPQL query is always a valid HQL query, the reverse is not true however.
change your query to
"from DataOrganization dataOrg where lower(dataOrg.poolName) like lower('%"+ poolName +"%')"
for more information have a look 14.3 doc
A good solution is:
List<OrganizationTB> resultList = null; Query query = session.createQuery("from DataOrganization dataOrg where lower(dataOrg.poolName) like lower(:poolName)"); query.setParameter("poolName", '%'+poolName+'%', StringType.INSTANCE); resultList = query.list();
So you protect your code from SQL injection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With