spring - setFirstResult and setMaxResult doesn't work well with Order By -
what cause criteriaquery
orderby
method stop working?
here implementations:
openjpaentitymanager kem = openjpapersistence.cast(entitymanager()); kem.getfetchplan().clearfetchgroups(); kem.getfetchplan().addfetchgroup("order_search"); criteriabuilder builder = kem.getcriteriabuilder(); criteriaquery<order> query = builder.createquery(order.class); root<order> order = query.from(order.class); query.select(order); predicate main_condition = buildwhereclause(builder, query, order, target_states, orderdate_from, orderdate_to, duedate_from, duedate_to, username); query.where(main_condition); query.orderby(builder.desc(order.get("orderdate"))); typedquery<order> q = entitymanager().createquery(query); if (firstresult != 0) q.setfirstresult(firstresult); if (maxresults != 0) q.setmaxresults(maxresults);
with pagniation, when there 15 records , want 5 records per page, should be:
-page1- 1 2 3 4 5 -page2- 6 7 8 9 10 -page3- 11 12 13 14 15
but here is
-page1- 1 2 3 4 5 -page2- 6 7 8 9 10 -page3- 5 4 3 2 1
the last page opposite order of first page, how come?
nail it, not myself, post quite helpful. did same , runs charm. need add primary key in order criteria otherwise pagination totally messed.
spend 4 hours , solution simple , tricky. works on openjpa 2.2.2 , oracle 11g, guess constant trick since openjpa 1.2 post.
Comments
Post a Comment