I\'ve crossed posted this in the FNH Google Group but here\'s the scoop:
I have a table in a legacy database that has a composite ID. Well, the PK is implied since t
Figured it out. You don't need to add the reference property for the parent. Notice how the many-to-one is missing in the adjusted mapping:
public AttachmentMap()
{
SchemaIs(Resources.CityworksDatabaseSchema);
WithTable(ObjectNames.TableWorkorderAttachment);
UseCompositeId()
.WithKeyReference(x => x.ParentWorkorder, "WORKORDERID")
.WithKeyProperty(x => x.FileLocation, "IMAGEPATH");
Map(x => x.AttachedByUser, "ATTACHEDBY").WithLengthOf(100).Nullable();
Map(x => x.AttachedOn, "DATETIMEATTACHED").Nullable();
Map(x => x.Comments).Nullable().WithLengthOf(256);
//References(x => x.ParentWorkorder, "WORKORDERID").FetchType.Join();
}
This results in the following HBM mapping file. The fix is to have the composite-id have a key-many-to-one line pointing back to the parent class. Now I can persist my Attachment class.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="">
<class name="Woolpert.Cityworks.Core.Entities.Azteca.Attachment, Woolpert.Cityworks.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="WorkOrderImg" xmlns="urn:nhibernate-mapping-2.2" schema="azteca">
<composite-id>
<key-many-to-one class="Woolpert.Cityworks.Core.Entities.Azteca.Workorder, Woolpert.Cityworks.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="ParentWorkorder" column="WORKORDERID" />
<key-property type="String" name="FileLocation" column="IMAGEPATH" />
</composite-id>
<property name="AttachedByUser" type="String">
<column name="ATTACHEDBY" length="100" not-null="false" />
</property>
<property name="AttachedOn" type="System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]">
<column name="DATETIMEATTACHED" not-null="false" />
</property>
<property name="Comments" type="String">
<column name="Comments" length="256" not-null="false" />
</property>
</class>
</hibernate-mapping>