2012-03-08 4 views
3

テーブルの予定から外部キーpatientIdを照会しようとしています。Hibernate 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(); 

私が試してみましたので、同じよう

は私のAppointmentオブジェクトが私のPatientオブジェクトにマッピングされている

(それはHQLのために重要かどうかを知りません) 「appt.appointmentId = 1」がうまく動作するため

createQuery("from Appointment as appt join appt.patientId ptid where ptid.patientId = 1").list(); 
私は根本的な何かが欠けする必要があります

:行うには、次のように参加します。どんな提案も感謝します。

答えて

14

HQLはオブジェクト照会言語であり、参照があるため、参照を最初に取得してIDを取得する必要があります。患者クラスが患者性を有すると仮定すると、

createQuery("from Appointment as appt where appt.patient.patientId = 1").list(); 
関連する問題