What I am trying to is really quite straigh forward, but I cannot seem to get the mapping right with NHibernate.
I am working up against a database with parent and child objects. The child objects have a foreign key reference to the primary key of the parent which is of datatype Guid. Pretty normal in any case. Now the database is set up in such a way that the foreign key field must never be null, so in case of orphan objects, with no parent, the foreign key should be an empty Guid ('00000000-0000-0000-0000-000000000000').
The way I set up Nhibernate is has been working fine for a long time, but recently I made the relationships bidirectional and then problems started arising. Obviously, NHibernate will see that the parent is null and attempt to save null to the foreign key field, but that is not allowed!
Example of the structure of the relationship mapping I am using follows below.
Parent side mapping:
<id name="ID" column="ID">
<generator class="guid" />
</id>
<bag name="Children" table="Children" lazy="false" cascade="all" inverse="true">
<key column="FK_OwnerID" not-null="true"/>
<one-to-many class="Childclass"/>
</bag>
Child side mapping:
<many-to-one name="Owner" column="FK_OwnerID" not-found="ignore" not-null="false" class="OwnerClass"/>
I have been trying with different properties but of no avail. Am I forced to use the insert="false" and update="false" properties and if so, how do I maintain the relationships exactly?
Thanks in advance for any help.