Here is a simple example:
session.createCriteria(A.class, "a")
.createAlias("a.cs", "c", JoinType.INNER_JOIN, Restrictions.eq("c.value", "C"))
.createAlias("a.bs", "b", JoinType.INNER_JOIN, Restrictions.eq("b.value", "B"))
.setProjection(Projections.id())
.list();
Here is the generated SQL:
select
this_.a_id as y0_
from
roct.A this_
inner join roct.B b2_ on this_.a_id=b2_.a_id and ( b2_.b_value=:1 )
inner join roct.C c1_ on this_.a_id=c1_.a_id and ( c1_.c_value=:2 )
And query parameters are:
Parameters "B" and "C" switched they order, which is incorrect.
If I change the order of joins in the criteria everything works fine:
session.createCriteria(A.class, "a")
.createAlias("a.bs", "b", JoinType.INNER_JOIN, Restrictions.eq("b.value", "B"))
.createAlias("a.cs", "c", JoinType.INNER_JOIN, Restrictions.eq("c.value", "C"))
.setProjection(Projections.id())
.list();
The generated query is:
select
this_.a_id as y0_
from
roct.A this_
inner join roct.B b1_ on this_.a_id=b1_.a_id and ( b1_.b_value=:1 )
inner join roct.C c2_ on this_.a_id=c2_.a_id and ( c2_.c_value=:2 )
And query parameters are:
Similar issues were reproduced with left outer joins.
|