I'm just getting started with Hibernate and have a general design question.
There are people and phone numbers. People can have multiples numbers and multiple people can have the same number.
I have created the following mapping:
Code:
<class name="Person" table="People">
<id name="ID" column="ID" type="Guid" access="nosetter.pascalcase-m-underscore" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid.comb"/>
</id>
<property name="FirstName" type="String" not-null="false" />
<property name="LastName" type="String" not-null="false" />
<property name="MiddleInitial" type="Char" not-null="false" />
<property name="DateOfBirth" type="DateTime" not-null="false" />
<joined-subclass name="DetailedPerson" table="DetailedPersons" proxy="DetailedPerson" extends="Person">
<key column="Person" />
<set name="PhoneNumbers" table="PersonPhoneNumbers">
<key column="Person" />
<many-to-many column="PhoneNumber" class="PhoneNumber" />
</set>
</joined-subclass>
</class>
<class name="PhoneNumber" table="PhoneNumbers">
<id name="ID" column="ID" type="Guid" access="nosetter.pascalcase-m-underscore" unsaved-value="00000000-0000-0000-0000-000000000000">
<generator class="guid.comb"/>
</id>
<property name="Number" type="string" not-null="false" />
<property name="Description" type="string" not-null="false" />
<set name="People" table="PersonPhoneNumbers" inverse="true">
<key column="PhoneNumber" />
<many-to-many column="Person" class="DetailedPerson" />
</set>
</class>
This works fine as long as the lookup table (PersonPhoneNumber) has just the two columns (the person ID and the phone number ID).
There is the mantra that any table, even lookup tables, should have a PK identify column. I tired adding one but my various stabs (rather in the dark) at it have proven fruitless. I won't enumerate the various things I tried as they all failed and are probably just noise.
The example in the hibernate's docs looks like the lookup table does not have a PK id column.
I know I could make the PK a composite of the two columns or I could just leave it as-is.
If I wanted to add a PK column that was given a guid.comb generated ID is that possible? If so - how, and is it even worth doing?
Thanks.
Robert.