繁体   English   中英

如何使用休眠联接列?

[英]How to use the Hibernate Join Column?

我有两个阶级,他们之间有联系。 无法理解问题出在哪里。 我用下一种方式编写代码。

 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;

并映射一个:

public class Prisvishche {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column
    private BigInteger prizv_id;

    @OneToMany(mappedBy = "prizv_id")
    private List<Abiturient> abiturients = new ArrayList();

您不能指向mappedBy的数据库列。 您必须指向一个实体字段,该实体字段是关系的拥有方,即:

 @ManyToOne(fetch = FetchType.LAZY)
 @JoinColumn(name = "prizv_id")
 private Prisvishche abiturients_pr;

因此,您拥有的一方应为:

@OneToMany(mappedBy = "abiturients_pr")
private List<Abiturient> abiturients = new ArrayList();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM