我正在做一个学校项目,目标是为一个虚构的药房制作一个 JavaEE 应用程序。
由于一种药物可以治疗一种或多种疾病,一种疾病可以由一种或多种药物治疗,我认为这是一个侧面和一个侧面的@OneToMany
关系。我也有实体。一个病人可能患有一种或多种疾病,一种疾病可能折磨许多病人。我对我的类进行了如下编码,但是当我尝试从实体生成表时,我的类和类之间出现了不兼容的映射异常。我在 Eclipse 中使用 GlassFish 服务器和 Derby 连接(一切都配置良好,所以这绝对是代码问题)。我的课程如下:Drug
@ManyToMany
Disease
Patient
Drug
Disease
public class Drug implements Serializable{
@OneToMany(targetEntity = Disease.class, mappedBy = "Cures_For_This_Disease")
private List<Disease> Diseases_Cured_By_This_Drug;
//other fields such as the name, price and origin of the drug
}
public class Disease implements Serializable{
@ManyToMany(targetEntity = Drug.class)
private List<Drug> Cures_For_This_Disease;
@ManyToMany(targetEntity = Patient.class)
private List<Patient> Afflicted_Patients;
//other fields such as name of disease etc.
}
public class Patient implements Serializable{
@OneToMany(targetEntity = Disease.class, mappedBy = "AfflictedPatients")
private List<Disease> Current_Diseases;
//other fields such as Patient name, social sec. nubmer etc
}
我究竟做错了什么?