在 HQL 中无关联地加入 [英] Join without association in HQL
问题描述
假设我有两个表(A,B),例如:
Lets say I have two tables(A, B) like:
A {id, a, c}
B {id, b, c}
我也有他们的实体.我想写一个 HQL,这样结果集就会像(其中 A.c = B.c):
I have also their entities. I want to write an HQL so that the result set will be like (where A.c = B.c):
(a1, b1, c1)
(a2, b2, c2)
(a3, b3, c3)
...
由于 on
子句不受 hibernate 支持,我被卡住了,我不知道如何编写查询.
Since on
clauses are not supported by hibernate I am stuck and I don't know how to write the query.
推荐答案
你必须使用交叉连接符号:
You have to use the cross join notation:
from A as table_a , B as table_b
where table_a.c = table_b.c
当然没有办法以这种方式实现外连接,所以如果是这种情况,你可能会遇到一些麻烦.
Of course there is no way to implement outer joins in this manner, so you might have some trouble if that's your case.
对于具有标准的类似情况,请参阅:hibernate-criteria-加入表没有映射关联
For the analogous case with criteria refer to: hibernate-criteria-joining-table-without-a-mapped-association
这篇关于在 HQL 中无关联地加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!