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...