File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Row counts with Hibernate Criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Row counts with Hibernate Criteria" Watch "Row counts with Hibernate Criteria" New topic

Row counts with Hibernate Criteria

Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

For our searching page, we are using Hibernate Criteria class to build the query at runtime.
The result page should employ Hibernate pagination facilities.
I have no problems running the query and getting the 50 record from the database, but how to get the whole number of matching records?
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
you have to use "Restrictions"

like: c.add( "firstName", "%" + filterValue + "%" )).setProjection(Projections.rowCount())
[ July 02, 2008: Message edited by: jim li ]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

So, you just want the count? Like the total number of records returned?

I guess you could simply do the query and ask the list for its size: list.size();

-Cameron McKenzie
I agree. Here's the link:
subject: Row counts with Hibernate Criteria
jQuery in Action, 3rd edition