-
1. Re: Many-Many CMP Relationship
giscard_aioba Aug 9, 2005 6:44 AM (in response to giscard_aioba)Hi again....
Well, Just to give more information, in my jbosscmp-jdbc.xml file I insert the relation-table-mapping tag to represent a M:N relationship.....
But inside this relation I don't see any foreign key to describe, so when I run the application the Jboss ask me by the COLUMN playerbean and teambean!?!?!?
My relationship is A player can play in many teams and a team could have many players!!!!!
Thanks all again.
Giscard -
2. Re: Many-Many CMP Relationship
hquang Oct 27, 2006 2:39 AM (in response to giscard_aioba)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@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>