I was hoping to get your thoughts on a problem I'm having with defining mappings for a table with a composite natural key. I've designed my core schema according to Wiley's "Data Model Resource Book" and it looks like this:
Party
- PK: PartyId
Person : Party
- Name
- BirthDate, etc.
Organization : Party
- Name
RoleType
- PK: RoleTypeId
- Description
PartyRole
- PK: PartyId (FK: Party)
- PK: RoleTypeId (FK: RoleType)
PartyRelationship
- PK: PartyIdFrom, RoleTypeIdFrom (FK: PartyRole)
- PK: PartyIdTo, RoleTypeIdTo (FK: PartyRole)
- PK: FromDate
- ThruDate, Status, Priority, etc.
I've mapped Person and Organization as joined subclasses of Party which is working well. I've mapped PartyRole to Party with a cascading set of RoleType objects related by the join table "PartyRole." Where I'm having trouble is with the relationship class.
Right now, I'm mapping PartyRelationship separately as:
Code:
<class name="Mvp.Objects.PartyRelationship, Mvp.Objects" table="PartyRelationship">
<composite-id>
<key-many-to-one name="From" class="Mvp.Objects.PartyRole, Mvp.Objects">
<column name="PartyIdFrom" />
<column name="RoleFrom"/>
</key-many-to-one>
<key-property name="FromDate" type="DateTime" />
<key-many-to-one name="To" class="Mvp.Objects.PartyRole, Mvp.Objects">
<column name="PartyIdTo"/>
<column name="RoleTo"/>
</key-many-to-one>
</composite-id>
</class>
I've also created a trigger to add PartyRole records to meet the foreign key constraints but I still have problems saving relationship objects (SQL update or delection failed - row not found). What's odd is that, when I do the same insert in Query Analyzer, it works fine. When hibernate does it via sp_executesql, it fails.
Do you see a simpler way to map this schema?
Thanks,
Jim