【问题标题】:JPQL query for entities belonging to another entity and satisfying certain conditionsJPQL 查询属于另一个实体并满足特定条件的实体
【发布时间】:2015-02-12 10:35:41
【问题描述】:

我有一个Patient 实体,其中包含Appointment 对象的列表。 Appointment 不知道Patient。我想创建一个 JPQL 查询来查找在指定日期之间属于特定患者的约会。看起来我需要在Appointment 中编写此查询,但由于Appointment 没有Patient 类型的字段,我发现这样做很难。

编辑(包含更多信息):

我知道我必须使用某种联接来执行此操作,但我对编写查询的联接了解不多。

编辑(带有实体链接):

Appointment

Patient

【问题讨论】:

  • 请显示 Patient 和 Appointment 实体的相关字段和关系。
  • 不要发布链接。贴出代码。

标签: java jpa join jpql


【解决方案1】:

您只需要加入:

select a from Patient p
join p.appointments a
where p.id = :patientId
and a.date between :start and :end

如果您对某事不太了解,了解更多信息的最佳方式是阅读the documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 2017-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    • 2021-06-14
    相关资源
    最近更新 更多