私は学校のプロジェクトに取り組んでおり、目標は架空の薬局用の JavaEE アプリケーションを作成することです。
1 つの薬で 1 つまたは複数の病気を治すことができ、1 つの病気は 1 つまたは複数の薬で治すことができるので、これは裏表の関係@OneToMany
であると考えました。私もエンティティを持っています。患者は 1 つまたは複数の病気に苦しんでいる可能性があり、1 つの病気が多くの患者を苦しめている可能性があります。クラスを次のようにコーディングしましたが、エンティティからテーブルを生成しようとすると、クラスとクラスの間で互換性のないマッピング例外が発生します。GlassFish サーバーと Eclipse で 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
}
私は何を間違っていますか?