-->
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: One-to-many with a twist
PostPosted: Mon May 30, 2005 5:01 am 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
Hi,
What is the best way to model this: Assume I have two objects: Agency and Publisher, and both have a 1-to-n relationship to Employee. This is a true 1-to-n relationship, as each Employee can only work for one Agency or one Publisher. Let's assume further that I cannot introduce a supertype (e.g. Employer) which holds the 1-to-n relationship.
My preferrd solution is to have a foreign key in Emplyee that can either link to a primary key of Agency or Publisher (all my primary keys are 64-bit IDs that are unqiue across the database). However, now I won't be able to map a bi-directional association, without indicating in Employee whether this is an "Agency" or "Publisher" relationship (ala <ANY>).
My other option is to use two tables, AgencyEmployee and PublisherEmployee, which can then be linked as traditional 1-to-n bidirectional associations.

What do you guys consider best practice in this situation?

Cheers,

Jen


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 8:45 am 
Newbie

Joined: Mon May 30, 2005 7:00 am
Posts: 1
Create a Superclass for Agency and Publisher (for example Company) and Link Employee to Company

This is common hibernate, please walk trough a tutorial :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 12:04 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
Thanks, that's what I would ideally do, but as I said in my post, I can't introduce a superclass (The above is just a simllified example, my actual object hierarchy is much more involved -- in a nutshell, I would need multiple inheritance to pull it off).
What do you think is my next-best option?

Thanks!

Jen


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.