Hibernate HQL-帮助查询外键 [英] Hibernate hql - help querying foreign key

查看:131
本文介绍了Hibernate HQL-帮助查询外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to query a foreign key patientId from table appointments.

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

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>

我的查询是:

    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"可以正常工作.任何建议将不胜感激.

I must be missing something fundamental because "appt.appointmentId = 1" works just fine. Any suggestions will be appreciated.

推荐答案

HQL是一种对象查询语言,由于您具有引用,因此需要首先访问该引用以获取ID.假设患者类别具有属性Patientid

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();

这篇关于Hibernate HQL-帮助查询外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆