-->
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.  [ 2 posts ] 
Author Message
 Post subject: fetch only the size of a collection (one-to-many)
PostPosted: Tue Jul 04, 2006 3:15 pm 
Newbie

Joined: Mon Aug 08, 2005 4:53 pm
Posts: 3
Is there a way of fetching only the size of a collection in a one to many association? For example: I have UserPojo with a collection of FonePojo. Can I use lazy for the one-to-many association and retrieve only the count of FonePojo without loading all related objects?

For example:
load(userPojo);
userPojo.getfones.size(); //retrieves the number of items but does not initialize the collection. is this possible?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 7:31 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Lots of ways of doing that. This one is from the ref docs, section 14.15, "Tips & Tricks":

Code:
You can find the size of a collection without initializing it:

( (Integer) session.iterate("select count(*) from ....").next() ).intValue();

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.