0 Replies Latest reply on Sep 28, 2004 1:38 PM by hubaghdadi

    Confused, create this field ?

    hubaghdadi

      Hey all.
      assume we have two CMP beans TeamBean, PlayerBean
      the relationship is one to many and bidirectional.
      TeamBean has the following CMP fields:
      name, city
      TeamBean has setter and getter methods for these fields.
      the database schema for TeamBean is :
      NAME, CITY
      PlayerBean has the following CMP fields :
      id, email
      PlayerBean has setter and getter methods for these fields.
      the database schema for PlayerBean is :
      ID, EMAIL, TEAM (TEAM is FK)
      I have the following code (in a facade bean):

      public void addPlayer(id, name, String team) {
       LocalPlayer lp = playerHome.create(id, name);
       LocalTeam lt = teamHome.findByPrimayKey(team);
       lp.setTeamLocal(lt);
      }
      

      the container will insert "a right" value at TEAM column of Player table.
      but I have read some articles that said :
      we should a CMP field called team in PlayerBean and create setter and getter methods for this CMP field.
      this is because (as the article says), we want to create a transfer object for PlayerBean with these fields :
      id, email, team
      so we able to write :
      new PlayerDO(local.getID( ), local.getEmail( ), local.getTeam( ));
      

      in my case (which I didn't create getTeam( )), I can write :
      new PlayerDO(local.getID( ), local.getEmail( ), local.getTeamLocal( ).getName( ));
      

      what is the right approach ??
      as far as I know, if we create a method like setTeam( ), this may damage the mapping
      that has been done by the container.
      should I create a CMP field called team and create setter and getter methods for it ?