From: Fabio M. (JIRA) <nh...@gm...> - 2011-05-31 12:11:51
|
[ http://216.121.112.228/browse/NH-941?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Fabio Maulo resolved NH-941. ---------------------------- Resolution: Fixed Fix Version/s: 3.2.0Beta2 > One-Many Requiring Nullable Foreign Keys > ---------------------------------------- > > Key: NH-941 > URL: http://216.121.112.228/browse/NH-941 > Project: NHibernate > Issue Type: Improvement > Components: Core > Affects Versions: 1.2.0.Beta2 > Reporter: Colin Jack > Priority: Major > Fix For: 3.2.0Beta2 > > > We are working with a legacy database and due to dependencies (DTS/reports etc) it is very difficult to redesign. > We are also trying to balance good database design with good domain driven design, hoping to find a good balance between the two. > One place that this falls down is when mapping a one-many where the key is in the many end. Regardless of whether this is good database design we do have to deal with it quite a lot in our database and it cannot be engineered out easily, we thus have to map our domain classes tothe database it is now. Unfortunately this means making the foreign key nullable which is obviously a big step back in terms of database quality. > I've read the forum entries about this, including [url]http://forum.hibernate.org/viewtopic.php?t=957582&highlight=foriegn+foreign+key+nullable[/url], but would like to suggest that you try to add support for non-nullable foreign keys in these situations as it would be a big help when working with existing databases. > [b]Hibernate version:[/b] 1.2 > [b]Mapping documents: > Main Table [/b] > <?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> > [b]Sub Table [/b] > <?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> > [b]Exception: [/b] > 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.. -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://216.121.112.228/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |