2 Replies Latest reply on Oct 27, 2006 2:39 AM by hquang

    Many-Many CMP Relationship

    giscard_aioba

      Hi guys....

      Well, I try to deploy my first CMP application, but I had a problem....

      When I have a Many-Many relationship where I indicate the fk names into the jbosscmp-jdbc.xml file?!?!

      For 1-1 and 1-Many I already know how to do...but for Many-Many I don't find where to write it?!?! would anyone help me!??!

      Thanks...

      Giscard

        • 1. Re: Many-Many CMP Relationship
          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

            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>