在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,以便结果集会像(其中Ac = Bc):
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-joining-table-without-a-mapped-关联
For the analogous case with criteria refer to: hibernate-criteria-joining-table-without-a-mapped-association
这篇关于在HQL中无需关联即可加入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!