-->
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.  [ 6 posts ] 
Author Message
 Post subject: List of List
PostPosted: Mon May 01, 2006 5:07 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 1:09 pm
Posts: 33
Hi,

I have many objects which can serve as parents. But actually, only very few of them do.

I have a child table with foreign keys to their parents, a common many-to-one relation.

In my program I want to print all a parent's children in one row, so I'd like to either have an array of all parent objects which actually do have children, or a list of lists of children, where each children list contains all the children of one parent.

In code this would either be:

Code:
Parent[] parents; //only the parents that actually have children


or:

Code:
Vector<Vector<Child>> childrenPerParent; //outer vector contains one list per parent


or:

Code:
Child[][] children;


Any suggestions will be highly appreciated.

-Marvin


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 9:45 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
well, if you're using hibernate, it seems like the first choice would make more sense. And each parent object has a list of its children.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 10:38 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 1:09 pm
Posts: 33
Of course. But I don't want to load ALL parent objects as many of them don't have any children at all.
I'm only interested in the ones with children.

I've tried this approach (from the parent class):

Code:
<set name="Children" inverse="true" cascade="delete">
    <key column="PARENT_ID" />
    <one-to-many class="Parent" />
</set>


And then I tried the followin HQL statement:

Code:
from Parent p where p.Children is not null


Unfortunately I get this error message:

Quote:
unindexed collection before [] [from Parent p where p.Children is not null]


Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 10:51 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 1:09 pm
Posts: 33
Oh, and I use NHibernate, but I don't think that makes any difference...


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 1:55 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
can't you just do a select all on the table with the "children" and order by the foreign key

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 01, 2006 1:58 pm 
Beginner
Beginner

Joined: Thu Dec 01, 2005 1:09 pm
Posts: 33
Yeah, got it to work now using "select distinct c.Parent from Child c".


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