-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Aggregation and Criteria queries
PostPosted: Mon Nov 20, 2006 2:44 pm 
Beginner
Beginner

Joined: Tue Sep 20, 2005 11:01 am
Posts: 25
Hibernate version:3.2

I have a Criteria object where the criteria is based on Query By Example (QBE):

Code:
Criteria crit = hSession.createCriteria(Facility.class).add(exampleFacility);


How do I create a query that will return the count of records, rather than the actual records themselves?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 9:59 pm 
Newbie

Joined: Mon Nov 20, 2006 8:32 pm
Posts: 3
try:

Criteria criteria = session.createCriteria(MyClass.class);
criteria.setProjection( Projections.rowCount() );
Integer count = (Integer)criteria.uniqueResult();

Check out projections in hibernate doc for more on this


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 10:00 am 
Beginner
Beginner

Joined: Tue Sep 20, 2005 11:01 am
Posts: 25
Many thanks. That was just what I needed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.