2012-03-08 64 views
3

我想從表約會中查詢外鍵的patientId。Hibernate hql - 幫助查詢外鍵

我的約會對象映射到我的病人對象(不知道這是否事項的HQL),像這樣:

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

和我的查詢是:

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

我曾嘗試做加盟,如:

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

我必須失去了一些基本的東西,因爲「appt.appointmentId = 1」的作品就好了。任何建議將不勝感激。

回答

14

HQL是一種對象查詢語言,由於您有一個引用,您需要先訪問引用以獲取該id。假設患者類別具有房產特性

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