-->
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: Mapping tree with parent child relations in another table
PostPosted: Tue Jun 23, 2009 6:07 pm 
Newbie

Joined: Fri Jan 05, 2007 5:36 am
Posts: 16
What I'm trying to do is map a tree structure.
I got groups that can have child groups, and the children can have their children and so on.

Here is how the database looks:

Groups

int Id
string Name

And then there is a pretty big problem. Here is the relations.

Group_Links

int ParentId
int ChildId

I have absolutely no clue about how to solve this and I can't change the existing database. There is already a lot of information in it. Have already tried a lot of things but can't get anything to work. Any help would be really appreciated! Thanks in advance!



Cheers,
Yagami


Top
 Profile  
 
 Post subject: Re: Mapping tree with parent child relations in another table
PostPosted: Wed Jun 24, 2009 2:52 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can map it as a plain bag with a many-to-many association

<bag name="Children" ....>
<many-to-many class="Group" column=".." table="group_links"
</bag>

if you need a reference from the child group to the parent, you need another bag with a many-to-many association to the parent. You can use a private field for that and define a property that returns the single parent that will be in that bag.

The main problem is how to efficiently retrieve a larger part of the tree, because you can't use FetchMode.Join in that special case.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Mapping tree with parent child relations in another table
PostPosted: Wed Jun 24, 2009 4:30 am 
Newbie

Joined: Fri Jan 05, 2007 5:36 am
Posts: 16
Thanks a lot for your reply! We have decided to wait with this and I'll continue with some other things that needs to be done.
The reason why this mapping problem exists is the database design is not quite what it should be in this case so it may be
possible to change the database if everything goes well.
I'll check out how well it goes with a many-to-many when done with the other things.


Thanks a lot for your help!


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.