2013-08-08 16 views
5

Czy można dołączyć tylko pierwszy wiersz (lub tylko dowolny inny wiersz, ale tylko jeden) za pomocą hql?Dołącz tylko pierwszy wiersz z 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) 

Jest to kod mam teraz, oczywiście

min(deliveryType.id) 

nie działa. Relacja między mg.modelId i config.objectId nie jest odwzorowana, a deliveryType jest listą. Nie mogę użyć wyraźnej przyczyny, której potrzebuję, aby móc zamówić przez deliveryType (to nie ma sensu, ale muszę to zrobić mimo to) i modelGroupName.

Odpowiedz

0
 
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) 
...