【问题标题】:Join only first row with HQL仅使用 HQL 加入第一行
【发布时间】:2013-08-10 11:01:58
【问题描述】:

是否可以使用 hql 只加入第一行(或任何其他行,但只有一个)?

select 
 config.id, mg.modelGroupName, min(deliveryType.id) 
from 
 NotificationConfig config, NotificationConfigEntry configEntry, SettlementModelGroup mg 
join 
 configEntry.notificationConfigEntryPK.user user 
join 
 configEntry.notificationConfigEntryPK.deliveryType deliveryType 
join 
 config.notificationType notifType 
join 
 notifType.objectType objectType 
where 
 config.id = configEntry.notificationConfigEntryPK.notificationConfig.id 
 and ( mg.modelId = config.objectId or config.objectId is null )

当然,这是我现在拥有的代码

min(deliveryType.id) 

不起作用。 mg.modelId 和 config.objectId 之间没有映射关系,deliveryType 是一个列表。我不能使用不同的原因,因为我需要能够按 deliveryType(这没有任何意义,但无论如何我都需要这样做)和 modelGroupName 来订购。

【问题讨论】:

    标签: hibernate join hql


    【解决方案1】:
    选择 config.id、mg.modelGroupName、deliveryType.id 从 NotificationConfig 配置、NotificationConfigEntry configEntry、SettlementModelGroup mg 加入 configEntry.notificationConfigEntryPK.user 用户 加入 configEntry.notificationConfigEntryPK.deliveryType deliveryType with deliveryType.id = (select min(id) from configEntry.notificationConfigEntryPK.deliveryType) ...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-08
      • 1970-01-01
      • 2012-10-11
      • 1970-01-01
      • 2013-09-10
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多