First of all, you will definitely need another table to maintain such a relationship:
The table, (maybe called SPEAKER_SUBSTITUTION) needs to have two columns, SPEAKER_ID and SUBSTITUTE_ID both of which reference the primary key of the SPEAKER table.
Now, you can map this relationship like below:
1. In your Speaker.hbm.xml :
<set name="substituteSpeakers" table="SPEAKER_SUBSTITUTION" cascade="save-update">
<key>
<column name="SPEAKER_ID" precision="5" scale="0" />
</key>
<many-to-many class="Speaker" column="SUBSTITUTE_ID"/>
</set>
2. Similarly, in the same file Speaker.hbm.xml there'l be another mapping:
<set name="speakers" table="SPEAKER_SUBSTITUTION" cascade="save-update">
<key>
<column name="SUBSTITUTE_ID" precision="5" scale="0" />
</key>
<many-to-many class="Speaker" column="SPEAKER_ID"/>
</set>
3. You'l need getters and setters in your Speaker.java for speakers and substituteSpeakers.
_________________ Excellence Inc
|