Hello!
I'm using hibernate 2.1.3 and have following problem:
There is a class Class1, which has properties prop1, prop2, prop3 which all constitute a composite id of Class1.
I have another class Class2 and Class2 has a bag of instances of Class2.
Each instance X in that bag (X instanceof Class2) has X.prop1 = Class2.id.
Class2 has a normal ID.
I have following XML definitions:
Class1:
Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Class1"
table="tbl_pred_seq" discriminator-value="N">
<composite-id>
<key-property name="predSeqPos" column="pred_seq_pos"/>
<key-property name="id" column="ID_pred_seq"/>
<key-many-to-one name="joining" class="Class2" column="ID_joining"/>
<key-many-to-one name="prevJoining" class="Class2" column="ID_prev_joining"/>
</composite-id>
</class>
</hibernate-mapping>
Class2:
Code:
<bag name="predecessorSequence" table="tbl_pred_seq"
cascade="save-update">
<key column="ID_joining" />
<many-to-many
class="Class1" />
</bag>
With these definitions I get this exception:
Code:
net.sf.hibernate.MappingException: Foreign key (tbl_pred_seq [elt])) must have same number of columns as the referenced primary key (tbl_pred_seq [pred_seq_pos,ID_pred_seq,ID_joining,ID_prev_joining])
How can I implement the bag in Class2 without modifying the database?
TIA
Dmitri