I am trying to query a foreign key patientId from table appointments.
my Appointment object is mapped to my Patient object (don't know if it matters for the hql) like so:
<many-to-one name="patient" class="application.model.Patient" fetch="select">
<column name="patientId" not-null="true" />
</many-to-one>
and my query is:
createQuery("from Appointment as appt where appt.patientId = 1").list();
I have tried to do joins like:
createQuery("from Appointment as appt join appt.patientId ptid where ptid.patientId = 1").list();
I must be missing something fundamental because "appt.appointmentId = 1" works just fine. Any suggestions will be appreciated.
HQL is a object query language and since you have a refernce you need to access the reference first to get the id. Assuming the patient class has a property patientid
createQuery("from Appointment as appt where appt.patient.patientId = 1").list();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With