Hi,
My goal is to make a polymorphic query (in HQL) and sort the results by type of class. The solution is to select through a "case..when.." the type (class) and order on this value. I want to give the "case..when..." an alias
clazz to order on it but I get a generic col_0_0_ instead :-(
HQL:
Code:
select case when p.class = Study then ('1' + p.name) when p.class = Organization then ('2' + p.name) when p.class = Notary then ('3' + p.lastName) when p.class = Person then ('4' + p.lastName) end [color=red]as clazz[/color], p.id, p.firstName, p.lastName, p.name, l.wordingFr, l.wordingNl, p.deceased from Party p left join p.locality as l
generated SQL:
Code:
select
top 50 case
when case
when party0_4_.NotaryId is not null then 4
when party0_3_.StudyID is not null then 3
when party0_1_.personId is not null then 1
when party0_2_.OrganizationID is not null then 2
when party0_.partyId is not null then 0
end=3 then '1'+party0_2_.name
when case
when party0_4_.NotaryId is not null then 4
when party0_3_.StudyID is not null then 3
when party0_1_.personId is not null then 1
when party0_2_.OrganizationID is not null then 2
when party0_.partyId is not null then 0
end=2 then '2'+party0_2_.name
when case
when party0_4_.NotaryId is not null then 4
when party0_3_.StudyID is not null then 3
when party0_1_.personId is not null then 1
when party0_2_.OrganizationID is not null then 2
when party0_.partyId is not null then 0
end=4 then '3'+party0_1_.lastName
when case
when party0_4_.NotaryId is not null then 4
when party0_3_.StudyID is not null then 3
when party0_1_.personId is not null then 1
when party0_2_.OrganizationID is not null then 2
when party0_.partyId is not null then 0
end=1 then '4'+party0_1_.lastName
end [color=red]as col_0_0_[/color],
party0_.partyId as col_1_0_,
party0_1_.firstName as col_2_0_,
party0_1_.lastName as col_3_0_,
party0_2_.name as col_4_0_,
locality1_.wordingFr as col_5_0_,
locality1_.wordingNl as col_6_0_,
party0_1_.IsDeceased as col_7_0_
from
Party party0_
left outer join
Person party0_1_
on party0_.partyId=party0_1_.personId
left outer join
Organization party0_2_
on party0_.partyId=party0_2_.OrganizationID
left outer join
Study party0_3_
on party0_.partyId=party0_3_.StudyID
left outer join
Notary party0_4_
on party0_.partyId=party0_4_.NotaryId
left outer join
LT_Locality locality1_
on party0_3_.LocalityId=locality1_.LocalityId