HQL like operator for case insensitive search

后端 未结 2 616
日久生厌
日久生厌 2021-02-05 04:08

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 & smal

相关标签:
2条回答
  • 2021-02-05 04:42

    change your query to

    "from DataOrganization dataOrg where lower(dataOrg.poolName)   
    like lower('%"+ poolName +"%')"
    

    for more information have a look 14.3 doc

    0 讨论(0)
  • 2021-02-05 04:55

    A good solution is:

    List<OrganizationTB> resultList = null;
    Query query = session.createQuery("from DataOrganization dataOrg where lower(dataOrg.poolName) like :poolName");
    query.setParameter("poolName", '%'+poolName.toLowerCase()+'%');
    resultList =  query.list();
    

    So you protect your code from SQL injection

    0 讨论(0)
提交回复
热议问题