如果我在单个实体 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;
??