Filter CriteriaQuery JPA 2.0 -
i making application java 1.6, jsf 2.0, jpa 2.0, primefaces 5.3 on weblogic server 10.3.6
i require implement lazy datatables burden modules , not make filter work.
this load method:
public list<t> load(int first, int pagesize, string sortfield, sortorder sortorder, map<string, object> filters) { // todo auto-generated method stub try { list<t> list = new arraylist<t>(); //criteria query criteriabuilder cb = this.ejbutils.getentitymanagerprivate().getcriteriabuilder(); criteriaquery<t> cq = cb.createquery(entityclass); //from root<t> = cq.from(entityclass); //sort if(sortfield != null){ if(sortorder == sortorder.ascending){ cq.orderby(cb.asc(from.get(sortfield))); }else{ cq.orderby(cb.desc(from.get(sortfield))); } } //filters if(!filters.isempty()){ list<predicate> predicates = new arraylist<predicate>(); (iterator<string> = filters.keyset().iterator(); it.hasnext();) { string filterproperty = it.next(); object filtervalue = filters.get(filterproperty); expression<string> literal = cb.upper(cb.literal((string)filterproperty.touppercase())); predicates.add(cb.like(literal, string.valueof("%" + filtervalue + "%").touppercase())); } cq.where(predicates.toarray(new predicate[predicates.size()])); } query q = this.ejbutils.getentitymanagerprivate().createquery(cq); list = q .setfirstresult(first) .setmaxresults(pagesize) .getresultlist(); this.setrowcount(this.ejbutils.count()); return list; } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); return null; } }
and @ log eclipselink , throws me this
[el fine]: 2016-07-15 11:15:35.415--serversession(1294563329)--connection(1645363733)--thread(thread[[active] executethread: '21' queue: 'weblogic.kernel.default (self-tuning)',5,pooled threads])--select * (select /*+ first_rows / a., rownum rnum (select id a1, action a2, activa a3, fecha_creacion a4, fecha_modificacion a5, nombre a6, usuario_creacion a7, usuario_modificacion a8, id_padre a9 se_opciones upper(?) ?) rownum <= ?) rnum > ? bind => [nombre, %rol%, 10, 0]
then when enter filter in datatable never brings results.
i fixed, replacing
predicates.add(cb.like(literal, string.valueof("%" + filtervalue + "%").touppercase()));
by
predicates.add(cb.like(cb.upper(from.get(filterproperty).as(string.class)), string.valueof("%" + filtervalue + "%").touppercase()));
Comments
Post a Comment