我有Team.class和Player.class,这些实体当然有更多的字段等。我想将Player扩展到不同的播放器类型而不需要在Team.class中进行更改。最佳解决方案是删除Player表并使FootballPlayer等表继承Player字段。
问题是如果没有球员桌但是足球和手球运动员牌桌,如何在Team.class中加入不同类型的球员?
@Entity
@Table(name = "Team")
public class Team {
private String name;
@ManyToMany(fetch = FetchType.LAZY)
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
@JoinTable(name = "TeamPlayer", joinColumns = {
@JoinColumn(name = "team_id", nullable = false, updatable = true) },
inverseJoinColumns = { @JoinColumn(name = "player_id",
nullable = false, updatable = true) })
private List<Player> players = new ArrayList<Player>();
@Entity
@Table(name = "Player")
public class Player extends User {
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "players")
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
private List<Team> teams = new ArrayList<Team>();