仅使用HQL加入第一行

时间:2013-08-08 16:15:53

标签: hibernate join hql

是否可以使用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。

1 个答案:

答案 0 :(得分:1)

select 
 config.id, mg.modelGroupName, deliveryType.id 
from 
 NotificationConfig config, NotificationConfigEntry configEntry, SettlementModelGroup mg 
join 
 configEntry.notificationConfigEntryPK.user user 
join 
 configEntry.notificationConfigEntryPK.deliveryType deliveryType with deliveryType.id = (select min(id) from configEntry.notificationConfigEntryPK.deliveryType)
...