0

如果我在单个实体 A 中与实体 B(用一对多注释)有多个关系(多对一)?我是否必须为 B 中每次出现的 A 添加注释?

例子:

实体 A:

@Entity
@Table(name = "patient")
@TableGenerator(name = "tab_gen_pa", initialValue = 30000, allocationSize = 1)
public class Patient implements Serializable, Comparable<Patient> {

 @ManyToOne
    @Column(name = "birth_region")
    private Region birthRegion;

    @ManyToOne
    @Column(name = "birth_province", length = 2)
    private Province birthProvince;

    @ManyToOne
    @Column(name = "birth_municipality")
    private Municipality birthMunicipality;

@Column(name = "living_region")
    @ManyToOne
    private Region livingRegion;

    @Column(name = "living_province", length = 2)
    @ManyToOne
    private Province livingProvince;

    @Column(name = "living_municipality")
    @ManyToOne
    private Municipality livingMunicipality;

实体 B:区域例如:

@Entity
@Table(name = "region")
@TableGenerator(name = "tab_gen_re", initialValue = 30, allocationSize = 1)
public class Region implements Serializable {

@OneToMany(mappedBy = "livingRegion")
    private List<Patient> patients;

我是否还必须在区域中插入:

@OneToMany(mappedBy = "birthRegion")
        private List<Patient> patientsBirthRegion;

??

4

1 回答 1

2

下面的一对关联映射,

@ManyToOne
@Column(name = "birth_region")
private Region birthRegion;


@OneToMany(mappedBy = "birthRegion")
private List<Patient> patientsBirthRegion;  

定义s 列表和它们的bidirectional association之间的唯一。现在,如果您想在这些区域中的 other和 the之间建立类似类型的关联,则需要在它们之间建立这种类型的关联映射。patientbirthRegionregionspatients

于 2013-10-04T12:55:57.777 回答