I have two classes . for example :
class A {
public Long id ;
}
class B {
public Long id ;
public A a ;
}
B and开发者_Go百科 A has many to one relationship. I can get List of B like this :
"from B b left join b.a a where a.id > 10 and b.id > 10 "
.
But how can I get List of A under the same join conditions ? I can't navigate A to B , Is there any solutions ? Can I do this by using criteria ?
ps : can I do it like this :
"select a from A a , B b where b.a.id = a.id
" ?
be careful with
select a from A a , B b where b.a.id = a.id
I think you may find two times the table A in the from clause of the final sql query (one due to the 'A a' from the hql from clause and the second one due to b.a.id in the where clause, automatically added by hibernate. (But i'm not sure of that, you will need to check it).
Isn't
select b.a from B b left join b.a a where a.id > 10 and b.id > 10
working ?
You examples should work, but have you tried:
select b.a from B b where b.id > 10 and b.a.id > 10
And yes, this should be possible with Criterias.
精彩评论