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
带有额外条件的 an(使用备选方案 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)
)