Hibernate hql-帮助查询外键

Hibernate hql-帮助查询外键,hibernate,hql,Hibernate,Hql,我正在尝试从表约会中查询外键patientId 我的约会对象映射到我的患者对象(不知道这对hql是否重要),如下所示: 我试过做一些类似的事情: createQuery("from Appointment as appt join appt.patientId ptid where ptid.patientId = 1").list(); 我一定错过了一些基本的东西,因为“appt.appointmentId=1”工作得很好。如果您有任何建议,我们将不胜感激。HQL是一种对象查询语言,

我正在尝试从表约会中查询外键patientId

我的约会对象映射到我的患者对象(不知道这对hql是否重要),如下所示:

我试过做一些类似的事情:

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

我一定错过了一些基本的东西,因为“appt.appointmentId=1”工作得很好。如果您有任何建议,我们将不胜感激。

HQL是一种对象查询语言,由于您有一个引用,您需要首先访问该引用以获取id。假设patient类具有patientid属性

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