wood burning stoves 2.0*
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
Author

Row counts with Hibernate Criteria

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3476

Hi.
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?
Thanks.
jim li
Ranch Hand

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

like: c.add( Restrictions.like( "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
    
    1

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: http://aspose.com/file-tools
 
subject: Row counts with Hibernate Criteria
 
Similar Threads
alternative for union hibernate criteira query
how to see the query that hibernate generates?
Get or Load all objects of a type
Reg : Criteria having where clause?
converting from Hibernate to JDBC???