-->
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: Hibernate criteria + count
PostPosted: Fri Dec 21, 2007 1:38 am 
Newbie

Joined: Thu May 24, 2007 3:01 am
Posts: 11
Hello friends,

When we retrieving records using criteria, is it possible to have a count as one of the columns.
My requirement is this.

For example we have loan table and borrower table. Say a loan may contain one or many borrowers. (1 borrower, multiple coborrower like that)
I want to list the loans with number of borrowers as one of the columns. How to do this with criteria?

Thank you,

Regards,
K.Siva


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 1:32 pm 
Beginner
Beginner

Joined: Wed May 16, 2007 7:12 am
Posts: 41
Location: London
Code:
       
Criteria crit = session.createCriteria(Product.class);
        crit.setProjection(Projections.rowCount());
        List results = crit.list();
        displayObjectList(results);


Please refer below for simple examples http://www.java2s.com/Code/Java/Hibernate/CatalogHibernate.htm

_________________
Dinesh Mahadevan

Visit me at http://www.yelani.com/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 24, 2007 2:22 am 
Newbie

Joined: Thu May 24, 2007 3:01 am
Posts: 11
this will tell only how many rows ie. row count. But what i need is, i want this count as one of the column along the lead details.

Thanks for your suggestions.


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.