I have the following hierarchy for a football match.
@Entity
public class Match {
@Id
@GeneratedValue
protected Integer id;
@Column(name = "home_team_id")
private int homeTeamId;
@Column(name = "away_team_id")
private int awayTeamId;
private TeamScore homeScore;
private TeamScore awayScore;
}
@Entity(name = "team_score")
public class TeamScore {
@EmbeddedId
protected TeamScoreId id;
private List<Goal> goals;
}
@Embeddable
public class TeamScoreId {
@Column(name = "match_id")
private Integer matchId;
@Column(name = "team_id")
private int teamId;
}
And I have a problem with mapping homeScore and awayScore in Match with TeamScore entity.
The first concern is whether two @OneToOne relations should be here. And how should they be configured?
The second one relates to matchId in TeamScoreId. How this mapping can be performed?