我需要解決這個問題:@OneToMany和@ManyToOne
@Entity
public class Team
{
@OneToMany // how mapped it ?
private List<Match> matches; // all played and coming matches
}
@Entity
public class Match
{
@ManyToOne
@Column(nullable = false)
private Team teamA;
@ManyToOne
@Column(nullable = false)
private Team teamB;
}
如果我有一個像場也Team team;
將通過mappedBy = team;
容易。
我可以使用列隊,而不是兩個字段,並添加@ManyToMany註釋,但它不是很好的解決方案恕我直言。
([指向在JPA /休眠相同實體的多個@ManyToOne字段]的可能的複製http://stackoverflow.com/questions/21345203/multiple-manytoone-fields-pointing-to-same-entity- in-jpa-hibernate) –
我看到了,但它並不令人興奮,這同樣的問題。 列表 matchesAsTeamA; + 列表 matchesAsTeamB; 而不是 列表匹配; 是不合邏輯的.. –
Bambelal