-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Many-to-Many mapping
PostPosted: Tue May 01, 2007 4:29 pm 
Newbie

Joined: Tue May 01, 2007 4:22 pm
Posts: 1
My domain object 'Speaker' needs to have many-to-many relationship with itself. A speaker object will have many substituteSpeakers and can be a substituteSpeaker for many other speaker.

How do it set this relationship?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 2:25 am 
Newbie

Joined: Tue Apr 17, 2007 9:02 am
Posts: 7
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.