Я пытаюсь создать сущности, но я получил следующую ошибку:
Internal Exception: Exception [EclipseLink-7157] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class application.Team] must use a @JoinColumn instead of @Column to map its relationship attribute [mPlayers].
Это мои сущности, мне нужно хранить данные в базе данных, используя Java Persistence API (JPA). Для этого я создаю объекты следующим образом. Возможно, я создал отношения между сущностями неправильно.
Персона
@MappedSuperclass
public class Person {
@Id
@GeneratedValue( strategy= GenerationType.AUTO )
protected int p_id;
protected String firstName;
protected String middleName;
protected String lastName;
protected String phone;
protected String email;
public Person() {
}
}
Игрок
@Entity
@Table( name = "tbl_players")
@AttributeOverride(name="id", column=@Column(name="player_id"))
public class Player extends Person implements Serializable{
private int player_id;
@Column(name = "goals_in_year")
private int numberOfGoalsInCurrentYear;
private boolean goalie;
@Column(name = "defended_goals")
private int defendedGoals;
public Player(){
}
}
Менеджер
@Entity
@Table( name = "tbl_manager")
@AttributeOverride(name="id", column=@Column(name="manager_id"))
public class Manager extends Person implements Serializable{
private String dob;
private int starRating;
@OneToOne
private Team teamToManage;
public Manager(){
}
}
Команда
@Entity
@Table( name = "tbl_team")
public class Team implements Serializable {
@Column(name = "team_name")
@Id
String teamName;
@OneToOne
Manager manager;
@Column(name = "team_players")
@OneToMany
private List<Player> mPlayers = new ArrayList<>();
@Column(name = "jersey_color")
String jerseyColor;
public Team(){
}
}
Лига
@Entity
public class League {
@Id
private int league_id;
@OneToMany
@Column(name = "League Teams")
private List<Team> mTeam = new ArrayList<>();
public void addTeam(Team team) {
mTeam.add(team);
}
public void removeTeam(Team team) {
mTeam.remove(team);
}
}