Leszek created Bug HHH-7834
Issue Type: Bug Bug
Affects Versions: 4.1.8
Assignee: Unassigned
Components: query-criteria
Created: 29/Nov/12 5:43 AM
Description:

Following code in Criteria Api:

Criteria criteria = getCriteria( RootClass.class );
criteria.createAlias( "b", "b" );
criteria.createAlias( "b.c", "c" );
criteria.createAlias( "a", "a", JoinType.INNER_JOIN, Restrictions.eqProperty( "a.keyId", "c.id" ) );

ignores order of adding aliases to criteria and produces following SQL query:

select [...]
from Root_Object this_
inner join A a3 on a3.KEY_ID = c2.ID
inner join B b1 on this_.ID = b1.COLUMN_ID
inner join C c2 on b1.ID = c2.COLUMN_ID

then MSSQL 2008 throws error:
SQLException: The multi-part identifier "c2.ID" could not be bound.

If I change the name of collection 'a' to 'z' in root entity then query:
select [...]
from Root_Object this_
inner join B b1 on this_.ID = b1.COLUMN_ID
inner join C c2 on b1.ID = c2.COLUMN_ID
inner join A z3 on z3.KEY_ID = c2.ID

returns correct results without error

Environment: Hibernate 4.1.8, MS SQL 2008 R2
Project: Hibernate ORM
Labels: criteria
Priority: Major Major
Reporter: Leszek
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira