JPA映射体育游戏与两个@OneToOne关系

时间:2018-04-22 11:33:40

标签: java hibernate jpa one-to-one

我有足够比赛的以下等级。

@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;
}

我在将HomeScore和awayScore映射到TeamScore实体时遇到问题。 第一个问题是两个@OneToOne关系是否应该在这里。它们应该如何配置? 第二个与TeamScoreId中的matchId有关。如何执行此映射?

0 个答案:

没有答案