I have 2 classes related to each other through a
uni-directional many-to-one relationship.
Parent Child
-------------------- -----------------
TradeInformation <-- TradeSchedule
When we update the TradeSchedule
(child) object, it also updates the parent even though the TradeInformation
(parent) hasn't been changed within the session.
We have other many-to-one mappings in our system and they do not exhibit the same behavior so I'm wondering this has something to do with the Schedule hierarchy or if we have missed something obvious...
Also from one session to the next, it would be great if you could mark
which classes are
NONMUTABLE. This could really speed up performance because NHibernate could ignore the objects marked as such on a session-by-session basis.
Here are our mappings...
TradeInformation.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyDomain" namespace="MyDomain.Trade" auto-import="true" >
<class name="TradeInformation" table="trade" lazy="false" dynamic-insert="true" dynamic-update="true">
<id name="Id" column="trade_id" type="Int32">
<generator class="native" />
</id>
<properties.../>
<many-to-one name="CurrentShape" class="MyDomain.Shapes.Shape" column="Shape_Id" access="field.camelcase"/>
<bag name="Details" table="trade_detail" inverse="true" cascade="all" fetch="select" lazy="false">
<key column="trade_id" />
<one-to-many class="TradeDetail" />
</bag>
</class>
</hibernate-mapping>
TradeScheduleCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assemblyMyDomain" namespaceMyDomain.Scheduling" auto-import="true" >
<subclass name="TradeSchedule" extends="Schedule" lazy="false" discriminator-value="T">
<many-to-one name="Trade" class="MyDomain.Trade.TradeInformation" column="trade_Id" access="field.camelcase"/>
</subclass>
</hibernate-mapping>
ScheduleCode:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyDomain" namespace="MyDomain.Scheduling" auto-import="true" >
<class name="Schedule" table="Schedule" lazy="false" dynamic-insert="true" dynamic-update="true">
<cache usage="read-write"/>
<id name="Id" column="schedule_id" type="Int32">
<generator class="native" />
</id>
<discriminator column="Schedule_Indicator" type="String" length="1"/>
<properties/>
<many-to-one name="Parent" class="Schedule" column="Parent_Id" access="field.camelcase"/>
<many-to-one name="CurrentShape" class="MyDomain.Shapes.Shape" column="shape_id" access="field.camelcase" not-null="false"/>
<bag name="Children" inverse="true" lazy="false" cascade="all">
<key column="Parent_Id"/>
<one-to-many class="Schedule"/>
</bag>
<bag name="Transactions" inverse="true" lazy="false" >
<key column="schedule_id"/>
<one-to-many class="ScheduleTransaction"/>
</bag>
<bag name="Internal_Details" inverse="true" lazy="false" cascade="all">
<key column="schedule_id"/>
<one-to-many class="ScheduleDetail"/>
</bag>
</class>
</hibernate-mapping>