Wrong SQL in order by clause when using joined subclasses
---------------------------------------------------------
Key: HHH-3577
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3577
Project: Hibernate Core
Issue Type: Bug
Components: core
Reporter: Hardy Ferentschik
Assignee: Steve Ebersole
The changes for HHH-2802 seem to have broken the following tests in Annotations:
* ManyToManyTest.testOrderByContractor()
* OneToManyTest.testOrderByOnSuperclassProperty()
Prior to the changes for HHH-2802 no table aliases where generated for in the SQL for
these tests. Since it is generally a problem to generate the right table alias in case of
joined subclasses there is a workaround in CollectionBinder.buildOrderByClauseFromHql()
line 910 where the table name is explicitly set in the oder by clause. This workaround
together with the changes for HHH-2802 now generate illegal SQL, eg:
select
contractor0_.EMPLOYER_ID as EMPLOYER1_1_,
contractor0_.CONTRACTOR_ID as CONTRACTOR2_1_,
contractor1_.id as id2_0_,
contractor1_1_.fld_name as fld2_2_0_,
contractor1_.hourlyRate as hourlyRate3_0_
from
EMPLOYER_CONTRACTOR contractor0_
left outer join
Contractor contractor1_
on contractor0_.CONTRACTOR_ID=contractor1_.id
left outer join
Employee contractor1_1_
on contractor1_.id=contractor1_1_.id
where
contractor0_.EMPLOYER_ID=?
order by
contractor1_.Employee.fld_name desc
Hibernate:
select
contractor0_.EMPLOYER_ID as EMPLOYER1_1_,
contractor0_.CONTRACTOR_ID as CONTRACTOR2_1_,
contractor1_.id as id2_0_,
contractor1_1_.fld_name as fld2_2_0_,
contractor1_.hourlyRate as hourlyRate3_0_
from
EMPLOYER_CONTRACTOR contractor0_
left outer join
Contractor contractor1_
on contractor0_.CONTRACTOR_ID=contractor1_.id
left outer join
Employee contractor1_1_
on contractor1_.id=contractor1_1_.id
where
contractor0_.EMPLOYER_ID=?
order by
contractor1_.Employee.fld_name desc
In this case 'contractor1_' is generated by the changes made for HHH-2802 whereas
'Employee' is added by the workaround. Note that even though Employee is not
working for all databases, the generated alias is wrong and should be
'contractor1_1_.
For now I commented out the failing tests since I cannot use the test skipping
functionality in Annotations yet.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: