创建JPA实体之间的关系时出错

问题描述 投票:0回答:1

我正在尝试创建实体,但出现以下错误。

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(){
    }
}

League

@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);
    }
}
java database entities jpa-2.1
1个回答
0
投票

这似乎是由于@Column(name =“ team_players”)和@OneToManyPlease

请阅读链接https://stackoverflow.com/a/24206471/11207493

© www.soinside.com 2019 - 2024. All rights reserved.