Have you used this Hibernate tools. Please have it downloaded. It will be handy. You can generate class files from the mapping just in a click. This way you can see yourself how Hibernate interprets things.
Your friend might be talking about something else.
Other tips:
First of all, I think Organization Contact is not a child of Organization. It can be said as a component of the Organization. However the way you have its own id makes people think this way. And the way you are moving all its columns, without any complaint, into the organization makes me to think like you have no problem in seeing organizationContact as a component of the Organization.
Anyways, option1 assumes you want a separate object (or entity) and its own lifecycle for organizationContact.
Option 1:
Java classes [Bi directional association]:
Code:
pub class Organization {
Integer orgId;
Set organizationContacts;
/* convenience method - to maintain Java references intact */
pub void addOrganizationContact (OrganizationContact orgContact) {
orgContact.setOrganization(this);
organizationContacts.add(orgContact)
}
}
pub class OrganizationContact {
Integer contactId;
Organization organization;
getter setter, etc
}
Organization.hbm.xmlCode:
<class name="Organization" table="organization">
. . . .
<!-- to access orgContacts from Organization -->
<set name="orgContacts" inverse="true">
<key column="org_id" />
<one-to-many class="OrganizationContact" />
</set>
</class>
OrganizationContact.hbm.xmlCode:
<class name="OrganizationContact" table="organization_contact">
. . . .
<id name="contact_id">
<generator class="..." />
</id>
<!-- to enable access from this side; access organization from an organizationContact-->
<many-to-one name="organization" column="org_id"
class="Organization" not-null="true" />
. . . .
</class>
Option 2:If you really do not want to access organization from organization contact objects, in other words we just care about association direction from organization to organizationContact and not the other way around, then Organization Contacts can be treated as components of Organization.
CLASS FILES:Code:
public class Organization {
.....
Set orgContacts ..;
....
}
public class OrganizationContact {
just other fields;
String contactName;
}
MAPPING FILES:Code:
<class name="Organization" table="organization">
<set name="orgContacts" table="org_contact" >
<key column="org_id" />
<composite-element class="OrganizationContact">
<property name="contactName" column="contact_name" not-null="true" />
. . . .
</composite-element>
</set>
</class>
Every property of the component should be not-null (while doing persistence decisions [insert or update], hibernate needs to compare copies).
In this Option2, there will NOT be any mapping file for OrganizationContact since it is a component of Organization, it has no object life on its own, it is a value type, it does not have its own id.
Please refer some books for other options or try out things with Hibernate Tools.