Spring integration Hibernate use hibernatetemplate does not support paging, so you need to package a class for paging, the implementation of the following ... Extend the functionality of Hibernatetemplate by using spring's hibernatetemplate callback mechanism for paging
/*** operation with HQL statement *@paramHQL *@paramOffset *@paramlength *@returnList*/ PublicList Getlistforpage (FinalString HQL,Final intOffset,Final intlength) {List List= Gethibernatetemplate (). Executefind (NewHibernatecallback () { PublicObject Doinhibernate (Session session)throwshibernateexception, SQLException {query Query=session.createquery (HQL); Query.setfirstresult (offset); Query.setmaxresults (length); List List=query.list (); returnlist; } }); returnlist; }/*** operation with criterion *@paramArg *@paramcriterions *@paramOffset *@paramlength *@returnList*/ protectedList Getlistforpage (FinalClass ARG,FinalCriterion[] Criterions,Final intOffsetFinal intlength) {List List= Gethibernatetemplate (). Executefind (NewHibernatecallback () { PublicObject Doinhibernate (Session session)throwsHibernateexception, SQLException {criteria Criteria=Session.createcriteria (ARG); //looping through the addition of constraint conditions for(inti = 0; i < criterions.length; i++) {Criteria.add (criterions[i]); } criteria.setfirstresult (offset); Criteria.setmaxresults (length); returncriteria.list (); } }); returnlist; } //get the total number of collections (aggregate query) PublicInteger Getsalechancelistcount () {FinalString hql = "SELECT count (*) from Salechanceinfo si"; Integer result=NULL; Result= (Integer) gethibernatetemplate (). Execute (NewHibernatecallback () { PublicObject doinhibernate (Session arg0)throwshibernateexception, SQLException {query Query=arg0.createquery (HQL); returnQuery.uniqueresult (); } }); returnresult; }
Integration of spring after hibernatetemplate implementation paging