I have two tables
Table A
ID int (PK)
ID2 int
Table B
ID int (PK)
A_ID int
A_ID2 int
I have created two classes one for table A named ClassA and one for table B named ClassB. A has a list with elements of B. Both ids of A are needed to find the entries in B.
classB.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate4.ClassB, NHibernate4" table="B">
<id name="ID" column="ID" type="int">
<generator class="increment"/>
</id>
</class>
</hibernate-mapping>
classA.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate4.ClassA, NHibernate4" table="A" lazy="false">
<id name="ID" column="ID" type="int">
<generator class="increment"/>
</id>
<property name="ID2" column="ID2" type="int"/>
<set name="Bs" table="B">
<key>
<column name="ID"/>
<column name="ID2"/>
</key>
<one-to-many class="NHibernate4.ClassB, NHibernate4"/>
</set>
</class>
</hibernate-mapping>
I get an exception during creating my factory
Foreign key (FKCDCAB7DE6C6BD79E:B [ID, ID2])) must have same number of columns as the referenced primary key (A [ID])
It is not a direct relation on the db side and i cann't change the db at the moment, it is the reason why i want to have hibernate so that i can start thinking about changing the db at all with all mapping in one place not scattered in dozens of files.
Any idea how i can get the list of Bs filled in A when i load one from the Db and stored as well?