We're updating the issue view to help you get more done. 

wrong order on the outer join with criteria restriction

Description

the generation of the sql create a error because of the outer join order.

Criteria criteria = session.createCriteria(Opportunity.class, "opportunity");
criteria.createAlias("opportunity.currency", "currency", JoinType.LEFT_OUTER_JOIN);
criteria.createAlias("opportunity.totalContractValueSplits", "tcv", JoinType.LEFT_OUTER_JOIN);
criteria.createAlias("currency.conversions", "conversions", JoinType.LEFT_OUTER_JOIN, Restrictions.conjunction()
.add(Restrictions.eqProperty("conversions.localCurrency", "currency.code"))
.add(Restrictions.eqProperty("conversions.effectiveMonth", "tcv.month"))
);

give :
select
this_.id as id1_2_4_,
this_.currency_id as currency2_2_4_,
currency1_.id as id1_0_0_,
currency1_.code as code2_0_0_,
conversion3_.currency_id as currency2_0_6_,
conversion3_.id as id1_1_6_,
conversion3_.conversions_KEY as conversi6_6_,
conversion3_.id as id1_1_1_,
conversion3_.currency_id as currency2_1_1_,
conversion3_.effectiveMonth as effectiv3_1_1_,
conversion3_.foreignCurrency as foreignC4_1_1_,
conversion3_.localCurrency as localCur5_1_1_,
tcv2_.opportunityId as opportun4_2_,
tcv2_.id as id1_3_,
tcv2_.id as id1_3_2_,
tcv2_.amount as amount2_3_2_,
tcv2_.currency_id as currency5_3_2_,
tcv2_.month as month3_3_2_,
tcv2_.opportunityId as opportun4_3_2_,
currency8_.id as id1_0_3_,
currency8_.code as code2_0_3_
from
opportunities this_
left outer join
currencies currency1_
on this_.currency_id=currency1_.id
left outer join
currency_conversions conversion3_
on currency1_.id=conversion3_.currency_id
and (
(
conversion3_.localCurrency=currency1_.code
)
)
left outer join
splits tcv2_
on this_.id=tcv2_.opportunityId
left outer join
currencies currency8_
on tcv2_.currency_id=currency8_.id
order by
tcv2_.month

I have attached the test case.
Cheers,
Alexis

Environment

hibernate 4.2
mysql

Status

Assignee

Unassigned

Reporter

alexis gayte

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.2.15

Priority

Major