我有一个JPA应用程序,该应用程序通过映射表关联两个对象:
围场
@Table(name = "wards")
public class Ward extends AbstractBaseEntity {
private static final long serialVersionUID = -5292952700297426004L;
@ManyToOne
@JoinColumn(name = "facility_id")
private Facility facility;
@Column(name = "name", length = 20, unique = false, nullable = false)
private String name;
}
床
@Table(name = "beds")
public class Bed extends AbstractBaseEntity {
@ManyToOne
@JoinColumn(name = "facility_id")
private Facility facility;
@Column(name = "name", length = 20, unique = false, nullable = false)
private String name;
}
映射对象:
@Entity
@Table(name = "locations")
public class Location extends AbstractBaseEntity {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "facility_id")
private Facility facility;
@Column(name = "ward", length = 40, unique = false, nullable = true)
private String ward;
@Column(name = "bed", length = 40, unique = false, nullable = false)
private String bed;
}
我想我正在做书,但是我不确定在所有三个对象中都包含设施代码是否很好。我应该只在Locations中使用便利还是在三个表中多次引用便利?以后管理对象有什么意义吗?我需要保证记录的管理尽可能一致。