Sorted subset of a list with hibernate -
i have domain object holding list containing many items. items order maintained hibernate (@ordercolumn). furthermore have double checked order column correctly set.
since list can long i've tried fetch items this:
query query = session.createquery("select d.list domainobject d d.key = :key"); query.setfirstresult(0); query.setmaxresults(10); query.list();
unfortunately returned list not ordered. way me ordered list modifying query this:
query query = session.createquery("select d domainobject d d.key = :key"); query.uniqueresult();
it seems hibernate doing item ordering when within domain object.
since later solution can have quite high memory impact i'd know if there way make hibernate return orderd subset of list.
criteria can used below. please change following code per requirements:
@override public list<certification> loadall() { criteria criteria = template.getsessionfactory().getcurrentsession().createcriteria(certification.class); criteria.setprojection(projections.projectionlist() .add(projections.property("certificationabbr"),"certificationabbr") .add(projections.property("certificationdesc"),"certificationdesc")) .addorder(order.asc("certificationabbr")) .setresulttransformer(transformers.aliastobean(certification.class)); return criteria.list(); }
Comments
Post a Comment