Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
AppFuseSupport




JSPWiki v2.2.33

[RSS]


Hide Menu

HibernatePagination


This is version 2. It is not the current version, and thus it cannot be edited.
[Back to current version]   [Restore this version]


Hibernate Pagination

  • Is there an easy way to get Hibernate to Paginate my results?

Here's an entry from the Hibernate FAQ that shows one way of doing this:

Query q = s.createFilter( collection, "" ); // the trivial filter
q.setMaxResults(PAGE_SIZE);
q.setFirstResult(PAGE_SIZE * pageNumber);
q.setProjection( Projections.alias( Projections.rowCount(), "numResults" ) )
List page = q.list();

Another blog entry relevant to this topic can be found here

The only limitation which the code snippet is that it does not had a method to return the total number of records (ie getLastPage()). Do NOT use

ScrollableResults scrollableResults = query.scroll();
scrollableResults.last();
rowCnt = scrollableResults.getRowNumber();

as most drivers (including Oracle) basically read all the data on the client side in order to calculate the number of rows. Hibernate 3 has added the ability of adding projections like count(*) w/ aliases to the Query.



Go to top   More info...   Attach file...
This particular version was published on 06-Nov-2006 13:52:48 MST by BenGill.