Can I load a property using HQL?

I am trying to understand how to load clients into the following HQL query:

select order.Customer
from Order as order
where order.Id in
(
  select itemId
  from BadItem as badItem
  where (badItemType = :itemType) and (badItem.Date >= :yesterday)
)

There is the usual many-to-one relationship between orders and customers.

I would like to do this in the request, as opposed to matching, if possible - as in "join fetch ..."

Maybe the request will be reorganized as a connection, and I have a mental block.

Any ideas?

+3
source share
1 answer
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)
)

EDIT:

:

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)
)
+5

Source: https://habr.com/ru/post/1764137/


All Articles