I am having problems saving my cross table for my many-to-many relationship. The table has additional fields so this isnt a simple m2m. Since my cross table has a dual column PK, the 2 FK ids, I am using composite-id.
Whats happening when I save is NH creates an UPDATE instead of INSERT. Ok, so I need a saved-value, but when i tried 'null' it returned a schema error. (looking in the code tehre is support for saved-value="null" it need to be added to the schema.) Using null wont work anyways becuase my composite isnt null it has the values I want to link.
Am I using the composite-id correctly? If I am, then how do i tell NH that my composite class is new vs updated?
cross table hbm:
Code:
<class name="ChangeOrder.Domain.CoEquipmentLocationProducts,ChangeOrder.Domain" table="CO_EQUIPMENT_LOCATION_PRODUCTS">
<composite-id name="OrderSection" class="ChangeOrder.Domain.OrderSection,ChangeOrder.Domain" unsaved-value="null">
<key-many-to-one name="ChangeOrderId" column="CHANGE_ORDER_ID" class="ChangeOrder.Domain.CoChangeOrder,ChangeOrder.Domain"/>
<key-many-to-one name="FormSectionId" column="FORM_SECTION_ID" class="ChangeOrder.Domain.CoFormSection,ChangeOrder.Domain"/>
</composite-id>
<many-to-one name="BaseProductId" column="BASE_PRODUCT_ID" class="ChangeOrder.Domain.CoBaseProduct,ChangeOrder.Domain" />
<many-to-one name="EquipmentLocationId" column="EQUIPMENT_LOCATION_ID" class="ChangeOrder.Domain.CoEquipmentLocation,ChangeOrder.Domain" />
</class>
composite class:
Code:
public class OrderSection
{
private CoChangeOrder order_section;
private CoFormSection form_section;
public OrderSection()
{
order_section = null;
form_section = null;
order_section_id = 0;
form_section_id = 0;
}
public CoChangeOrder ChangeOrderId
{
get { return order_section; }
set {order_section = value; }
}
public CoFormSection FormSectionId
{
get { return form_section; }
set {form_section = value; }
}
public override bool Equals( object obj ) {...}
public override int GetHashCode() {...}
}