gpt4 book ai didi

java - Hibernate Spring 注解混淆

转载 作者:行者123 更新时间:2023-12-02 11:03:47 25 4
gpt4 key购买 nike

我对 S.H. Annotation 感到困惑。这是我的代码我的第一个类:

@Entity
@Table(name="player")
public class Player implements Serializable
{
@Id
@Column(name="id_player")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
private String pseudo;
}

还有我的第二堂课:

@Entity
@Table(name="team")
public class Team implements Serializable
{
@Id
@Column(name="id_team")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "player")
private Set<Player> players = new HashSet<Player>();
}

它抛出异常:

mappedBy reference an unknown target entity property: Player.Team in Team.players

我在这些类中有 getter 和 setter。我怎样才能让它发挥作用?谢谢!

最佳答案

将其添加到Player类中:

@ManyToOne(fetch = FetchType.LAZY)

private Team team;

并替换为Team类:

mappedBy = "player" ----> mappedBy = "team"

关于java - Hibernate Spring 注解混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51137114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com