[英]How to use the Hibernate Join Column?
I have two classes and relations between them. 我有两个阶级,他们之间有联系。 Can`t understand where the problem is.
无法理解问题出在哪里。 I write code in the next way.
我用下一种方式编写代码。
public class Abiturient {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, unique = true, length = 11)
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "prizv_id")
private Prisvishche abiturients_pr;
And mapped one: 并映射一个:
public class Prisvishche {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column
private BigInteger prizv_id;
@OneToMany(mappedBy = "prizv_id")
private List<Abiturient> abiturients = new ArrayList();
You cannot point to a database column in a mappedBy
. 您不能指向
mappedBy
的数据库列。 You have to point to an entity field that is the owning side of the relationship and that is: 您必须指向一个实体字段,该实体字段是关系的拥有方,即:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "prizv_id")
private Prisvishche abiturients_pr;
So your owned side should be: 因此,您拥有的一方应为:
@OneToMany(mappedBy = "abiturients_pr")
private List<Abiturient> abiturients = new ArrayList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.