We are working with a legacy database and due to dependencies (DTS/reports etc) it is very difficult to redesign.
One place that this falls down is when mapping one-many because in many cases we put the key into the many end and in in those situations we need to make the foreign key nullable, which is less than perfect.
I've read the forum entries about this, including
http://forum.hibernate.org/viewtopic.php?t=957582&highlight=foriegn+foreign+key+nullable, but wondered if your going to support non-nullable foreign keys in these situations in the future as it would be a big help when working with existing databases.
Hibernate version: 1.2
Mapping documents:
Main Table
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SevenIM.FeeSettings.Domain.FeeTemplateDefinition, SevenIM.FeeSettings.Domain" table="FeeTemplateDefinition" lazy="false">
<id name="Id" column="FeeTemplateDefinitionID">
<generator class="identity" />
</id>
<version name="_version" column="Version" access="field" />
<property name="Description" column="Description" access="nosetter.camelcase-underscore"/>
<!-- need to map to fee template -->
<bag name="_feeCalculationSettingTemplates" access="field" cascade="all-delete-orphan" lazy="true">
<key column="FeeTemplateSettingID" />
<one-to-many class="SevenIM.FeeSettings.Domain.FeeCalculationSettingTemplate, SevenIM.FeeSettings.Domain" />
</bag>
</class>
</hibernate-mapping>
Sub Table
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SevenIM.FeeSettings.Domain.FeeCalculationSettingTemplate, SevenIM.FeeSettings.Domain" table="FeeTemplate" lazy="false">
<id name="Id" column="FeeTemplateID">
<generator class="identity" />
</id>
<version name="_version" column="Version" access="field" />
<property name="Kind" column="FeeTypeID" access="nosetter.camelcase-underscore"/>
</class>
</hibernate-mapping>
Exception:
Test method SevenIM.FeeSettings.Persistence.Tests.FeeTemplatePersistenceTests.CanPersist threw exception: NHibernate.ADOException: could not insert: [SevenIM.FeeSettings.Domain.FeeCalculationSettingTemplate] ---> System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'FeeTemplateDefinitionID', table 'CRM.dbo.FeeTemplate'; column does not allow nulls. INSERT fails.
The statement has been terminated..