Take this code as an example:
/**
* A person has one or more contacts
*/
class Person {
String personId;
Set contacts;
}
/**
* A contact is related to one person.
*/
class Contact {
Person contactOf;
String emailAddress;
}
I'm relatively new with hibernate, but to the best of what I can determine, the relation must be modelled in the domain layer as such: with the Contact containing an instance of Person, as opposed to this:
class Contact {
String contactOfId;
String emailAddress;
}
This is perfectly okay except when, for example, I have a screen to allow the user to enter in a contact information, I would typically just pass the PK of the person and then associate the contact to the person using the PK.
In the hibernate scenario, it appears that I need to materialize a Person object, attach it to the Contact, and then call "session.save(contact)".
I guess I could craft an insert to do it explicitly, but it seems like overkill. Would much prefer it if hibernate could do the association by itself without the extra step of retrieving the Person object.
Thanks!
Ed.Q.B.
|