I have a model like this:
class Foo
{
public IList<HistoryRecord> History {get;set;}
public HistoryRecord HistoryReference {get;} //Computed, null or item from History.
}
Which I tired to map like this:
<list name="History" cascade="all-delete-orphan" inverse="false" table="history">
<key column="foo_fk" not-null="true" update="false"/>
<index column="idx"/>
<one-to-many class="HistoryRecord" />
</list>
<many-to-one name="HistoryReference" cascade="none" access="readonly" column="history_ref" class="HistoryRecord"/>
It works but produce, redundant SQL:
- INSERT INTO foo... --not specifying history_ref, it inserts NULL.
- N INSERTS INTO history.. all good.
- UPDATE foo set history_ref=, prop1=, prop2=, etc NH redundantly updates history_ref, which could be inserted at 1. and all properties of Foo.
I want to get rid of 3. redundant update and set history_ref during insert.