-->
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: parent child within a single table
PostPosted: Tue Nov 13, 2007 2:32 pm 
Regular
Regular

Joined: Thu Nov 30, 2006 10:48 am
Posts: 59
We have a Unit object (military Unit that represents the army hierarchy - e.g. Division is a Unit; a Division can contain a Brigade which is a Unit). We use a single table, tblUnit, with a parentUnitID (foreign key to the same table). The parentUnitID can be null. How is this modeled in hibernate/nHibernate?

Note that we also have a Unit object hierachy with different types of Units persisted using the single table, tblUnit (table-per-class-hierarchy); this means we want both relationships.

Thanks,
Bill

_________________
metazone


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 14, 2007 9:03 am 
Senior
Senior

Joined: Thu Feb 09, 2006 1:30 pm
Posts: 172
Have you tried mapping it just as you say? The Unit has a Parent Unit property which references the Unit, and then the Unit also has a ChildrenUnits collection which references the units that point to this unit as it's parent? I hope that isn't too confusing.

I believe that mapping should work fine. Did you run in to issues when you tried it? We've done hierarchies before, but it was always through a join table (many-to-many relationships).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 14, 2007 9:06 pm 
Regular
Regular

Joined: Thu Nov 30, 2006 10:48 am
Posts: 59
Thanks -- yes, it does work.

_________________
metazone


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.