So here is the deal I have 2 tables that look like this...
User:
ID
Name
Address:
ID(User)
Type
Line1
Line2
....
Where the PK for Address is a combination of ID and Type.
Here is my mapping file...
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
auto-import="true">
<class name="AutomatedGrantSuggestions.DataAccess.Organization, AutomatedGrantSuggestions.DataAccess" lazy="false" table="ct_org_master">
<id name="CtId" column="ct_id">
<generator class="native" />
</id>
<property name="Name" column="ct_org_name1"/>
<property name="Name2" column="ct_org_name2"/>
<many-to-one name="Address" class="AutomatedGrantSuggestions.DataAccess.Address, AutomatedGrantSuggestions.DataAccess"/>
</class>
<class name="AutomatedGrantSuggestions.DataAccess.Address, AutomatedGrantSuggestions.DataAccess" lazy="false" table="ct_org_address">
<composite-id>
<key-property name="CtId" column="ct_id" />
<key-property name="Type" column="ct_org_addr_type"/>
</composite-id>
<property name="CtId" column="ct_id"/>
<property name="Line1" column="ct_org_addr1"/>
<property name="Line2" column="ct_org_addr2"/>
</class>
</hibernate-mapping>
But when I run my tests I get the following error...
Quote:
Test 'AutomatedGrantSuggestions.DataAccess.Tests.OrganizationIntegrationTest.TestRetrieveHibernateFromIDWithAddress' failed:
Test method AutomatedGrantSuggestions.DataAccess.Tests.OrganizationIntegrationTest.TestRetrieveHibernateFromIDWithAddress threw exception: NHibernate.FKUnmatchingColumnsException: Foreign key (FK4961A1696CC0F1CB:ct_org_master [Address])) must have same number of columns as the referenced primary key (ct_org_address [ct_id, ct_org_addr_type]).
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
HibernateUtils.cs(47,0): at AutomatedGrantSuggestions.DataAccess.HibernateUtils.OpenSession()
HibernateUtils.cs(25,0): at AutomatedGrantSuggestions.DataAccess.HibernateUtils.getOrg(Int32 orgId)
OrganizationIntegrationTest.cs(167,0): at AutomatedGrantSuggestions.DataAccess.Tests.OrganizationIntegrationTest.TestRetrieveHibernateFromIDWithAddress()
Any Ideas?