select customer
from BadItem as badItem
join fetch badItem.Order as order
left join fetch order.Customer as customer
where (badItemType = :itemType) and (badItem.Date >= :yesterday)
これを機能させるには、BadItem が Order に関連していない場合は、BadItem と Order の間に関係を追加するか、inner join
追加の条件で を使用する必要があります (代替 2 を使用する場合はパフォーマンスに注意してください)。
別:
select customer
from Order as order
join fetch order.Customer as customer
where order.Id in
(
select itemId
from BadItem as badItem
where (badItemType = :itemType) and (badItem.Date >= :yesterday)
)
編集:
どうですか:
select customer
from Order as order
join fetch order.Customer customer
join fetch customer.orders
where order.Id in
(
select itemId
from BadItem as badItem
where (badItemType = :itemType) and (badItem.Date >= :yesterday)
)