我可以使用 HQL 预先加载属性吗?
我正在尝试弄清楚如何在以下 HQL 查询中急切加载客户:
select order.Customer
from Order as order
where order.Id in
(
select itemId
from BadItem as badItem
where (badItemType = :itemType) and (badItem.Date >= :yesterday)
)
订单和客户之间通常存在多对一关系。
如果可能的话,我想在查询中而不是映射中执行此操作 - 就像在“连接获取...”中一样
,也许查询会被重构为连接,而我有一个心理障碍。
有什么想法吗?
I'm trying to work out how to eager load the customers in 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's the usual many-to-one relationship between orders and customers.
I'd like to do this is in the query, as opposed to the mapping, if possible - as in a "join fetch..."
Maybe the query would be refactored as a join and I'm having a mental block.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,如果 BadItem 与 Order 无关,您需要添加 BadItem 和 Order 之间的关系,或者使用带有额外条件的
内连接
(使用替代方案 2 时注意性能)。替代方案:
编辑:
怎么样:
For this to work you will need to add the relationship between BadItem and Order if BadItem is unrelated to Order, or use an
inner join
with extra conditions (watch out for performance when using alternative 2).Alternative:
EDIT:
What about: