2013-08-08 50 views
5

Chỉ có thể tham gia hàng đầu tiên (hoặc bất kỳ hàng nào khác nhưng chỉ có một) bằng cách sử dụng hql?Chỉ tham gia hàng đầu tiên với 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) 

Đây là mã tôi đang gặp ngay bây giờ, tất nhiên

min(deliveryType.id) 

không hoạt động. Mối quan hệ giữa mg.modelId và config.objectId không được ánh xạ, và deliveryType là một danh sách. Tôi không thể sử dụng nguyên nhân khác biệt tôi cần để có thể đặt hàng bằng deliveryType (điều này sẽ không làm cho bất kỳ ý nghĩa, nhưng tôi cần phải làm cho nó anyway) và modelGroupName.

Trả lời

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) 
... 
Các vấn đề liên quan