Hey guys,
Hoping you can help me with this problem. it's really starting to get a little annoying. I'm sure it's something i'm missing in the mapping files, but i just can't seem to sort it.
Basically I've got a table that has a NULLABLE foreign key. As far as i know the mapping files for both tables have been set-up properly (you can see each of these below). Each table knows of the other etc. (many-to-one and one-to-many)... however, when i try and save the many-to-one table WITHOUT a value set in the foreign key table it fails giving a standard SQL error message saying that there was a foreign key constraint problem.
This is of course an error message i would expect to receive if either:
a) the foreign key did NOT accept nulls or
b) i had set the foreign key ID to one that doesn't exist
Neither of these are true. in fact to make sure i've set the objectA.objectB = null. just in case nhibernate is trying to set it's value to zero or something.
Any ideas people? I'm sure it's just something i've missed in the mapping files.... which can be seen below:
ContentField.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="App.Domain.Classes" assembly="App.Domain" default-access="property">
<class name="App.Domain.Classes.EntityField, App.Domain" table="EntityField">
<id name="Id" type="Int32" unsaved-value="null">
<column name="EntityFieldID" length="4" sql-type="int" not-null="true" unique="true" index="PK_ContentEntryField"/>
<generator class="identity" />
</id>
<many-to-one name="ContentEntry" class="App.Domain.Classes.ContentEntry, App.Domain">
<column name="ContentEntryId" length="4" sql-type="int" not-null="false"/>
</many-to-one>
</class>
</hibernate-mapping>
ContentEntry.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="App.Domain.Classes" assembly="App.Domain" default-access="property">
<class name="App.Domain.Classes.ContentEntry, App.Domain" table="ContentEntry">
<id name="Id" type="Int32" unsaved-value="null">
<column name="ContentEntryId" length="4" sql-type="int" not-null="true" unique="true" index="PK_ContentEntry"/>
<generator class="identity" />
</id>
<bag name="EntityFields" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="ContentEntryId"/>
<one-to-many class="App.Domain.Classes.EntityField, App.Domain"/>
</bag>
</class>
</hibernate-mapping>
It is the ContentField table that i am trying to create a record for without the ContentEntry foreign key set...
Looking forward to your replies and help.
Ben