I seem to be having problems with the many-to-one association. I have an object that in the database has a foreignkey reference to a category object. If I don't attempt to link these to objects together in the mapping files (i.e. leave out the many-to-one association) they load fine (I've tested loading them both separately using their respective mapping files). However when I add in the many-to-one association, I get a LoadByUnqiueKey exception and the inner exception is "object reference not set to an instance of the object". Below is the mapping file with the many-to-one association:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GL.Objects" namespace="GL.Objects.Common">
<class name="CodeDefinition" table="CodeDef" dynamic-update="true" dynamic-insert="true" select-before-update="true">
<id name="ID" type="Int32" column="CodeDefID" unsaved-value="null" >
<generator class="NHibernate.Id.IdentityGenerator" />
</id>
<property name="Value" column="CodeValue" type="Byte" />
<property name="Description" column="CodeDescr" type="String" />
<property name="UserAdded" column="UserAdded" type="String" />
<property name="DateAdded" column="DateAdded" type="DateTime" />
<property name="UserEdited" column="UserEdited" type="String" />
<property name="DateEdited" column="DateEdited" type="DateTime" />
<property name="IsDeleted" column="IsDeleted" type="Boolean" />
<many-to-one name="Category" class="GL.Objects.Common.Category" column="CodeCategoryID" cascade="none" fetch="join" property-ref="ID" not-found="ignore" />
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GL.Objects" namespace="GL.Objects.Common">
<class name="Category" table="CodeCategory" dynamic-update="true" dynamic-insert="true" select-before-update="true">
<id name="ID" type="Int32" column="CodeCategoryID" unsaved-value="null" >
<generator class="NHibernate.Id.IdentityGenerator" />
</id>
<property name="Name" column="CategoryDescr" type="String" />
<property name="Notes" column="Notes" type="String" />
<property name="UserAdded" column="UserAdded" type="String" />
<property name="DateAdded" column="DateAdded" type="DateTime" />
<property name="UserEdited" column="UserEdited" type="String" />
<property name="DateEdited" column="DateEdited" type="DateTime" />
<property name="IsDeleted" column="IsDeleted" type="Boolean" />
</class>
</hibernate-mapping>
In the first mapping file, you'll see the many-to-one association. This seems to be item causing the problem but I can't figure out why. According to the documentation I have, this seems to be correct. Can anyone shed some light?
Thanks!