简体   繁体   中英

JPQL query for entities belonging to another entity and satisfying certain conditions

I have a Patient entity which holds a list of Appointment objects. Appointment has no knowledge of Patient . I would like to create a JPQL query which finds appointments that belong to a specific patient between specified dates. It looks as if I need to write this query inside Appointment but since Appointment does not have a field of type Patient , I am finding it difficult to do so.

Edit (with more information):

I know I have to do it using some sort of join but I don't know much about joins to write the query.

Edit (with links to entities):

Appointment

Patient

You simply need a join:

select a from Patient p
join p.appointments a
where p.id = :patientId
and a.date between :start and :end

Whe you don't know much about something, the best way to know more about it is to read the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM