Hi,
I'm using NHibernate 1.2.1 and I've got a question concerning compositeId and a many-to-one relation:
Object A has got a composite id (Id1 and Id2). Some other object are implementing a many-to-one relation and are accessing to this object through the composite id. Everything's fine.
Object A (excerpt)
Code:
<composite-id>
<key-property name="Id1" column="ID1" />
<key-property name="Id2" column="ID2" />
</composite-id>
Any other Object accesses to it by:
Code:
<many-to-one name="myReference" class="ObjectA">
<column name="ForeignID1" />
<column name="ForeignID2" />
</many-to-one>
But the evil Object B has also a many-to-one relation and want's to access to object A, but only by using the first part of the composite id (Id1), because the use of both keys would return a different set of data.
Code:
<many-to-one name="myReference" class="ObjectA">
<column name="ForeignID1" />
</many-to-one>
I've got an error when I try create my nhibernate session saying "Foreign key in table B must have same number of columns
as referenced primary key in table A". I understand what this means cause I normally use both parts of the composite id.
But is there a way only to use one part of the key and ignore the second?
As I'm dependend to an existing data model and as
I'm not mighty to change this data model, I'm searching for a way to connect my objects through this many-to-one relation using only the first part of the composite-id.
Any ideas, hints or remarks?
Thanks, aggn