Hibernate hql - foreign key query

I am trying to query a foreign key client for an id from a table.

my Assignment object maps to my Patient object (don't know if it matters for hql):

    <many-to-one name="patient" class="application.model.Patient" fetch="select">
        <column name="patientId" not-null="true" />
    </many-to-one>

      

and my request:

    createQuery("from Appointment as appt where appt.patientId = 1").list();

      

I 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 would be appreciated.

+3


source to share


1 answer


HQL is an Object Query Language, and since you have a link, you need to access the link first to get the ID. Assuming patient class has patientid property



createQuery("from Appointment as appt where appt.patient.patientId = 1").list();

      

+14


source







All Articles