-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: BUG IN HIBERNATE:alias for case..when..then..end NOT WORKING
PostPosted: Tue Sep 02, 2008 4:22 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
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



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.