2 Replies Latest reply on Jun 15, 2004 11:24 AM by sbocquet

    EJB 1-N Relationships

    sbocquet

      Hi,

      I have an 1-N relationship between 2 CMP EJBs, Matches and Leagues, which is set correctly (XDoclet generated). A league can have several matches, and a match can only have one league.

      I'm trying to retrieve the league name, which is a league EJB field, while I'm listing every matches.
      e.g. :
      team 1 vs team 2 - League 1
      team 3 vs team 4 - League 2...

      Here is the descriptor for the relationship.

       <ejb-relation >
       <ejb-relation-name>MatchesLeaguesRelation</ejb-relation-name>
      
       <ejb-relationship-role >
       <ejb-relationship-role-name>MatchesHasLeague</ejb-relationship-role-name>
       <multiplicity>Many</multiplicity>
       <relationship-role-source >
       <ejb-name>Matches</ejb-name>
       </relationship-role-source>
       <cmr-field >
       <cmr-field-name>league</cmr-field-name>
       </cmr-field>
       </ejb-relationship-role>
      
       <ejb-relationship-role >
       <ejb-relationship-role-name>LeagueHasMatches</ejb-relationship-role-name>
       <multiplicity>One</multiplicity>
       <relationship-role-source >
       <ejb-name>Leagues</ejb-name>
       </relationship-role-source>
       <cmr-field >
       <cmr-field-name>matches</cmr-field-name>
       <cmr-field-type>java.util.Collection</cmr-field-type>
       </cmr-field>
       </ejb-relationship-role>
       </ejb-relation>
      


      I have a finder in the League EJB, which can retrieve all the matches of a League
       * @ejb.finder signature="java.util.Collection findMatches(java.lang.String aLeagueId)"
       * query = "SELECT OBJECT(M) FROM League L, IN (L.match) AS M WHERE L.LeagueId = ?1"
      


      But I don't know how to have the League name while I'm listing the matches!!!...
      Perhaps, I have pissed something with XDoclet ?
      Can someone help me?

      Thanks a lot

        • 1. Re: EJB 1-N Relationships
          sbocquet

          Hi,

          I'm thinking in getting the League FK, and then to do a Leagues.findByPrimaryKey() with it. Am I wrong ?

          How can I have the League Foreign Key in Matches, because the field is a relation field and it don't appears in my interface !!!

          • 2. Re: EJB 1-N Relationships
            sbocquet

            Hi,

            It's Ok now.
            I have just forgotten a tag with Xdoclet, and the relationship method was not generated in the interfaces.

            Bye