[jboss-user] [Beginners Corner] - Re: Many-Many CMP Relationship

hhtquang do-not-reply at jboss.com
Fri Oct 27 02:39:27 EDT 2006


Hi,

I have 3 tables 
1. PLAYER: field PLAYER_ID
2. TEAM: field TEAM_ID
3. TEAM_PLAYER: fields PLAYER_ID and TEAM_ID
And I also have 2 entities: PlayerBean and TeamBean.
Make sure that you have getter and setter for cmr fields teams and players in ejb-jar.xml are added into PlayerBean and TeamBean respectively.

The relationship btw TEAM AND PLAYER is n:n
Pls refer to ejb-jar.xml and jbosscmp-jdbc.xml, it will help to solve your problem.U can email me at hhtquang at yahoo.com for more info.

ejb-jar.xml: 

<ejb-relation>
    <ejb-relation-name>player-team</ejb-relation-name>
    <ejb-relationship-role>
	<ejb-relationship-role-name>player-has-teams</ejb-relationship-role-name>
	Many
	<relationship-role-source>
	    <ejb-name>PlayerBean</ejb-name>
	</relationship-role-source>
	<cmr-field>
	    <cmr-field-name>teams</cmr-field-name>
	    <cmr-field-type>java.util.Collection</cmr-field-type>
	</cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
	<ejb-relationship-role-name>team-has-players</ejb-relationship-role-name>
	Many
	<relationship-role-source>
	    <ejb-name>TeamBean</ejb-name>
	</relationship-role-source>
	<cmr-field>
	    <cmr-field-name>players</cmr-field-name>
	    <cmr-field-type>java.util.Collection</cmr-field-type>
	</cmr-field>
    </ejb-relationship-role>
</ejb-relation>
 
jbosscmp-jdbc.xml

<ejb-relation>
    <ejb-relation-name>player-team</ejb-relation-name>
    <relation-table-mapping>
	<table-name>TEAM_PLAYER</table-name>
    </relation-table-mapping>
    <ejb-relationship-role>
	<ejb-relationship-role-name>player-has-teams</ejb-relationship-role-name>
	<key-fields>
	    <key-field>
		<field-name>playerId</field-name>
		<column-name>PLAYER_ID</column-name>
	    </key-field>
	</key-fields>
    </ejb-relationship-role>   
    <ejb-relationship-role>
	<ejb-relationship-role-name>team-has-players</ejb-relationship-role-name>
	<key-fields>
	    <key-field>
		<field-name>teamId</field-name>
		<column-name>TEAM_ID</column-name>
	    </key-field>
	</key-fields>
    </ejb-relationship-role>
</ejb-relation>




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3981229#3981229

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3981229



More information about the jboss-user mailing list