Scrollable iteration in Hibernate by R4R Team

When we want to use the JDBC driver supports scrollable ResultSets, the Query interface can be used to obtain a ScrollableResults object that allows flexible navigation of the query results.

Query q = sess.createQuery("select, student from DomesticStudent student " + "order by");
ScrollableResults students = q.scroll();
if ( students.first() ) {

    // Here we can find the first name on each page of an alphabetical list of cats by name
    firstNamesOfPages = new ArrayList();
        String name = students.getString(0);

    while ( cats.scroll(PAGE_SIZE) );

    // Now get the first page of students
    pageOfCats = new ArrayList();
    int i=0;
    while( ( PAGE_SIZE > i++ ) && ) pageOfCats.add( cats.get(1) );


We have to remember is that an open database connection and cursor is required for this functionality. Use setMaxResult()/setFirstResult() if you need offline pagination functionality.
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!