HQL留下了不相关实体的连接 [英] HQL left join of un-related entities
问题描述
我有两个实体, A
和 B
。它们是相关的,但我不想将关系映射添加到bean。
I have 2 entities, A
and B
. They are related but I do not want to add the relationship mapping to the beans.
我们如何在 A之间使用左外连接和
B
使用HQL或标准?
How can we use left outer join between A
and B
using HQL or criteria?
有一些解决方法可用于此,
There are some workarounds available for this,
- Use Native SQL as told here.
- Add a relationship and use select a from A a left join a.b.
- We can do a inner join in the HQL as select * from A a, B b where a.some=b.some
我总是回顾这两个选项,对此有没有其他选择?或者这样做是不可能的?
I was always going back these 2 options, is there any alternative for this? Or this in not possible?
推荐答案
目前,使用HQL的where子句中加入不相关类的theta样式仅支持内部连接。
Currently, the theta-style on joining the unrelated classes in the where clause using HQL only supports inner join.
请求为了支持这种情况的外连接,目前是第3次投票最多的增强,但我不认为这个功能将在近端功能中实现,因为它需要重新实现当前基于ANTLER的查询解析器,这似乎是一项巨大的IMO任务。
The request for supporting the outer join for such situation is currently the 3-rd most voted enhancement but I don't think this feature will be implemented in the near feature as it requires the re-implementation of the current ANTLER-based query parser first which seems to be a gigantic task IMO.
如果您坚持使用HQL执行左连接而不添加A和B之间的关系,则可以使用选项3首先执行内连接,然后使用follow ng HQL
If you insist to use the HQL to perform left join without adding the relationship between A and B , you can use option 3 to do the inner join first, then use the following HQL
from A a where a.some not in ( select b.some from B)
查找所有无法加入B并以编程方式结合结果的A。
to find out all the A that cannot join B and combine the results programmatically .
自版本5.1.0开始 HHH-16(Explicit joins on unrelated classes) is fixed,we should be能够加入不相关的实体。
As of release 5.1.0 HHH-16 (Explicit joins on unrelated classes) is fixed and we should be able to join the unrelated entities.
这篇关于HQL留下了不相关实体的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!