Suppose I have two object Patient and its MedicalRecord with OneToMany relation.
i.e.
class Patient {
...
@OneToMany(mappedBy = "patient")
List<MedicalRecord> mr;
...
}
class MedicalRecord {
...
@ManyToOne
Patient patient;
Date createdAt;
...
}
Now I want to work with the MedicalRecord(s) within one month. What is the best way to do this?
I know i could do it using JPQL with @NamedQuery or @Query. But I don't feel it's as good as I expected. Can I do this without issuing JPQL query and stay in the object domain? For example to add constraint on the "Patient.mr" field so that only records within one month will be retrieved and I can iterate through them without worrying about unnecessary database fetch?
Thanks!