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: nhibernate and tree hierachy
PostPosted: Wed Aug 23, 2006 5:47 am 
Newbie

Joined: Wed Jul 12, 2006 5:57 am
Posts: 3
Hi all,

I use Hibernate for a short period of time and now I'm facing a complex problem. I try figure it out what is the best practice for the following scenario:
I have the following classes: Department, Team, Position, all of them inherited from a Entity class even there is almost no difference between them. But I wanted different classes for different entities.
I try to create a tree hierachy, each object is with all others in a bidirectional one-to-many relationship. For example a Department can have Teams and Positions as children and a Position can have Departments and Teams as children.
I created the mapping files and I loaded the tree without problems. But I cannot user general methods because in every moment I have to know the type of the parent and the type of the child in order to call the proper method for save/update/delete.

How can I avoid this and implement a more general way to work with this relationships in the tree?
What is the best approach for this issue?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 23, 2006 9:22 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
the best approach when you have a hierarchy like this is to have set cascade on all the collections.
In this case you can update only the root object. every update/insert/delete in your child collections will be cascaded so you don't need delete/insert/update methods for every type of object in the hierarchy.
Also your hierarchy should be implemented as a composite.

hth,
radu


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.