-->
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: Fetching children count in parent/child relationship
PostPosted: Thu Feb 26, 2004 12:23 pm 
Newbie

Joined: Thu Jan 29, 2004 3:52 pm
Posts: 16
Hi,

In a parent/child one-to-many relationship how can one set a property of a parent that is equal to the count of children? Of course you can use a separate query but I was wondering if there is a way to get the count property of the parent initialized transparently. I also do not want to load all children objects and then simply do children.size() due to that fact that there are potentially thousands of children.

I was thinking of using a formula as a subquery when loading a parent, but I could not figure how to do it since it seems that sql query in formula definition can not accept parameters.


Regards,
Vladimir


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 28, 2004 8:17 pm 
Newbie

Joined: Thu Jan 29, 2004 3:52 pm
Posts: 16
Hi,

Formula actually works as I wanted. For each loaded parent object, the formula:
Code:
select count(*) from CHILD i where i.parent = id
gets executed. The id of the parent is set appropriately for each parent load. Very nice Hibernate.

Regards,
Vladimir


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.