I'm trying to use MyBatis to map a one-to-many relationship in my data model. This is based on the following classes:
class Team{
String mId;
String mName;
List<Player> mPlayers;
}
class Player{
String mId;
String mName;
}
I would like to write a query that returns a list of matches, each populated with the tags that correspond to that match.
<select id="getTeams" resultType="Team" resultMap="TeamMap">
SELECT id, name, players.id as player_id, players.name as player_name
FROM teams
JOIN players ON teams.id = players.team_id
</select>
<resultMap type="Team" id="TeamMap">
<id property="mId" column="id"/>
<result property="mName" column="name"/>
<collection property="mTags" javaType="List" ofType="Player">
<id property="player_id" column="mId"/>
<result property="player_name" column="mName"/>
</collection>
</resultMap>
But the problem I'm having with this is that each Team object is only populated with a single Player. How can I change this to ensure that each team contains all players that belong to it?