HQL留下了不相关实体的连接 [英] HQL left join of un-related entities

查看:127
本文介绍了HQL留下了不相关实体的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个实体, 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,


  1. 按照

  2. 添加关系并使用从A中选择一个左连接ab

  3. 我们可以在HQL中执行内部连接,如 select * from a a,B b其中a.some = b.some

  1. Use Native SQL as told here.
  2. Add a relationship and use select a from A a left join a.b.
  3. 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子句中加入不相关类的t​​heta样式仅支持内部连接。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆