Hi-
I need some help on a many-to-many mapping. I have:
Table A:
A1, B1, C1 (composite primary key)
Table B:
B2, C2, D2 (composite primary key)
B1 = B2, C1 = C2. There is a many-to-many relationship between Class1 (table A) and Class2 (Table B).
I have tried the following:
Code:
<class name="Class1" table="TableA">
<composite-id name="key" class="Class1PK">
<key-property name="keyA1" type="long" column="A1"/>
<key-property name="KeyB1" type="long" column="B1"/>
<key-property name="KeyC1" type="long" column="C1"/>
</composite-id>
....
<set name="members" table="TableB" lazy="true">
<key>
<column name="B1"/>
<column name="C1"/>
</key>
<many-to-many class="Class2" outer-join="false">
<column name="D2"/>
</many-to-many>
</set>
</class>
and:
<class name="Class2" table="TableB" mutable="false">
<composite-id name="key" class="Class2PK">
<key-property name="keyB2" type="long" column="B2"/>
<key-property name="keyC2" type="long" column="C2"/>
<key-property name="keyD2" type="long" column="D2"/>
</composite-id>
....
</class>
And I end up with this exception:
net.sf.hibernate.MappingException: Foreign key (TableB [D2])) must have same number of columns as the referenced primary key (TableB [A1,B1,D2]])
If you know the solution you can probably see that I can't figure out which column goes where. I tried other combinations without success. I would appreciate any help on the subject.
Thanks