however the decision graph take a wrong decision when it generate order of the Sql createAlias, the Restrictions . conjunction() is at the bad place and generate a sql error.
{code} criteria.createAlias("a.b", "b", JoinType.LEFT_OUTER_JOIN); criteria.createCriteria("a.d", "d", JoinType.LEFT_OUTER_JOIN); criteria.createCriteria("b.c", "c", JoinType.LEFT_OUTER_JOIN, Restrictions.conjunction() .add(Restrictions.eqProperty("c.code", "b.code")) .add(Restrictions.eqProperty("c.month", "d.month")) ); {code}
generate
{code} select this_.id as id1_0_5_, this_.b_id as b_id2_0_5_, b1_.id as id1_2_0_, b1_.code as code2_2_0_, c6_.B_id as B_id1_2_7_, c3_.id as c_id2_3_7_, c3_.id as id1_4_1_, c3_.code as code2_4_1_, c3_.month as month3_4_1_, d8_.A_id as A_id1_0_, d2_.id as d_id2_1_, d2_.id as id1_5_2_, d2_.a_id as a_id3_5_2_, d2_.b_id as b_id4_5_2_, d2_.month as month2_5_2_, a10_.id as id1_0_3_, a10_.b_id as b_id2_0_3_, b11_.id as id1_2_4_, b11_.code as code2_2_4_ from A this_ left outer join B b1_ on this_.b_id=b1_.id left outer join B_C c6_ on b1_.id=c6_.B_id and ( ( c3_.code=b1_.code and c3_.month=d2_.month ) ) left outer join C c3_ on c6_.c_id=c3_.id and ( ( c3_.code=b1_.code and c3_.month=d2_.month ) ) left outer join A_D d8_ on this_.id=d8_.A_id left outer join D d2_ on d8_.d_id=d2_.id left outer join A a10_ on d2_.a_id=a10_.id left outer join B b11_ on d2_.b_id=b11_.id
{code}
That created a error : {color:red} Unknown column 'c3_.code' {color} The error is : the join's order are wrong.
Cheers |
|