I am trying to get a one to one mapping working correctly and no matter what I do, I can't get the saves to cascade correctly.
I have an Account object and a BillingAddress object that is a subclass of an Address object.
Whenever I try to issue a save on the Account, the BillingAddress persistence action is an update instead of an insert.
I am obviously doing something wrong, but I can't figure out what it might be.
The Account Object:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="[Apptik_Security].[dbo]" assembly="ApptikFramework.Domain" namespace="ApptikFramework.Domain.Entities.Security" >
<class name = "Account" table= "[Account]" select-before-update="true">
<id name="_system_ObjectId" access="field" column="System_ObjectId" type="System.Guid" >
<generator class="guid" />
</id>
<version column="System_Version" name="System_Version" type="System.Int64" unsaved-value="negative" />
<many-to-one name="BillAddress" class="ApptikFramework.Domain.Entities.Security.BillingAddress, ApptikFramework.Domain" column="BillAddressId" unique="true" cascade="all-delete-orphan" />
</class>
</hibernate-mapping>
The Address object:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="[Apptik_Security].[dbo]" assembly="ApptikFramework.Domain" namespace="ApptikFramework.Domain.Entities.Security" >
<class name = "Address" table= "[Address]" select-before-update="true" discriminator-value="0" >
<id name="_system_ObjectId" access="field" column="System_ObjectId" type="System.Guid" >
<generator class="guid" />
</id>
<discriminator column="AddressType" type="System.Byte" />
<version column="System_Version" name="System_Version" type="System.Int64" unsaved-value="negative" />
<subclass discriminator-value="1" name="ApptikFramework.Domain.Entities.Security.BillingAddress, ApptikFramework.Domain">
</subclass>
<subclass discriminator-value="2" name="ApptikFramework.Domain.Entities.Security.MailingAddress, ApptikFramework.Domain" />
</class>
</hibernate-mapping>
When I issue a save on the above, the account gets INSERTed BUT the address object SQL that is executed is an UPDATE statement and not an insert statement.
Any help is greatly appreciated.