以下にマップされた3つのエンティティクラスがあります。
@Table(name = "PROVIDER")
public class Provider implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private long id;
private long npi;
private String name;
private String specialization;
@OneToMany(mappedBy = "provider", cascade = REMOVE)
@OrderBy
private List<Treatment> treatments;
@Transient
private ITreatmentDAO treatmentDAO;
// and so forth
}
@Table(name = "PATIENT")
public class Patient implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private long id;
private long patientid;
private String name;
@Temporal(TemporalType.DATE)
private Date birthDate;
@OneToMany(cascade = REMOVE, mappedBy = "patient")
@OrderBy
private List<Treatment> treatments;
// and so forth
}
@Table(name = "TREATMENT")
public abstract class Treatment implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private long id;
private String diagnosis;
@ManyToOne
@JoinColumn(name = "patient_fk", referencedColumnName = "id")
private Patient patient;
@ManyToOne
@JoinColumn(name = "provider_fk", referencedColumnName = "id")
private Provider provider;
// and so forth
}
患者またはプロバイダーのいずれかで getTreatments を呼び出すと、JPA が治療属性に入力することが期待されます。ただし、これはプロバイダーに対してのみ機能します。何を試しても、patient.getTreatments() は常に空を返します。
私は何が欠けていますか?
サーバー側での単体テストは次のとおりです。
@Test
public void TestAddTreatment() throws PatientExn, ProviderExn {
GregorianCalendar bd = new GregorianCalendar();
bd.set(1977, 03, 13);
Patient patient = this.pf.createPatient(900L, "Orezi.Dauda", bd.getTime());
Provider provider = this.prf.createProvider(6777L, "Sam.OKafor");
this.pdao.getEntityManager().getTransaction().begin();
this.pdao.addPatient(patient);
this.pdao.getEntityManager().getTransaction().commit();
this.prdao.getEntityManager().getTransaction().begin();
this.prdao.addProvider(provider);
provider.addDrugTreatment(900L, "Malaria", "Chloroquine", (float)5.0);
this.prdao.getEntityManager().getTransaction().commit();
List<Long> providerTids = this.prdao.getProviderByNpi(6777L).getTreatmentIds();
List<Long>patientTids = this.pdao.getPatientByPatientId(900L).getTreatmentIds();
assert(providerTids.size() == 1); //Passes
assert(patientTids.size() == 1);// Fails
}