spring - Cannot use expression in where clause -
i want implement server-side filtering of datatable. here service method retrieving list :
@override @transactional public list<user> list(int start, int length, string search, int triidx, string ordretri) { string hql = "from user "; if (!search.equals("") && search != null) { hql = hql.concat(" "); if (numberutils.isnumber(search)) hql = hql.concat(" salary "); else hql = hql.concat(" lower(username) "); hql = hql.concat(" lower('%:critere%') "); } if (ordretri.equals("asc")) { switch (triidx) { case 0: hql = hql.concat(" order username "); break; case 1: hql = hql.concat(" order email "); break; case 2: hql = hql.concat(" order salary "); break; default: hql = hql.concat(" order username "); break; } } else { switch (triidx) { case 0: hql = hql.concat(" order username desc"); break; case 1: hql = hql.concat(" order email desc"); break; case 2: hql = hql.concat(" order salary desc"); break; default: hql = hql.concat(" order username desc"); break; } } query query = sessionfactory.getcurrentsession().createquery(hql); query = query.setparameter("critere",search); query = query.setfirstresult(start); query = query.setmaxresults(length); @suppresswarnings("unchecked") list<user> listuser = (list<user>) query.list(); return listuser; }
at runtime datatable alert error data. wrong in code ?
hql.concat(" lower('%:critere%') ")
should rewrittent :
hql.concat(" :critere ") query = query.setparameter("critere", "%" + search.tolowercase(locale. ....) + "%");
Comments
Post a Comment