This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Get or Load all objects of a type
Reg : Criteria having where clause?
how to see the query that hibernate generates?
converting from Hibernate to JDBC???