Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
935 views
in Technique[技术] by (71.8m points)

hibernate - Join without association in HQL

Lets say I have two tables(A, B) like:

A {id, a, c}
B {id, 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)
...

Since on clauses are not supported by hibernate I am stuck and I don't know how to write the query.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

For the analogous case with criteria refer to: hibernate-criteria-joining-table-without-a-mapped-association


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...