These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: One-Many Requiring Nullable Foreign Key
PostPosted: Tue Mar 13, 2007 4:04 pm 
Beginner
Beginner

Joined: Fri Sep 08, 2006 2:55 am
Posts: 21
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..


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.