-->
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: Association modeling question...
PostPosted: Fri Mar 12, 2004 7:08 pm 
Newbie

Joined: Fri Mar 12, 2004 6:44 pm
Posts: 4
Semi-newbie here with a question on how to model something using Hibernate.

I have a Person object, which relates to several email addresses, ore of which can be the primary email address.

I'd like to have the following API:

Code:
class Person {
  EmailAddress getPrimaryEmail();
  Set getEmails();
}


Can anyone suggest how to model this in Hibernate? Logically, "primary email" is a 1-to-1 association and "emails" is a 1-to-many. My database schema isn't set yet, so I'm free to design this any way that makes sense. It seems cleanest to have a Person table and EmailAddress table. But given how Hibernate maps a 1-to-1 as either a unique foreign key or a primary key association, I don't see how I can have that along with a 1-to-many mapped to the same table (since there may be non-primary EmailAddresses that map to the same Person).

Apologies if the "right design" is really obvious...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 7:15 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i think you'll need an id_mail on your person table to cover the primary mail.
You also need the id_person on the mail table to cover the list of mails.

By doing this, you'll be able to have

class Person {
Int idPerson;

EmailAddress getPrimaryEmail(); // i suggest you to have a many to one relation here even if there always be only one person assigned to his primary key
Set getEmails(); // here comes a one to many
}


This will be easier for the relational model, but it's only my point of view, you can go with one-to-one too


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.