-->
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.  [ 6 posts ] 
Author Message
 Post subject: Alias for case..when..then..end not working
PostPosted: Thu Aug 21, 2008 7:08 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
The specified HQL:

select
u,
case..when..then..end as myalias
from User u

doesn't generate the specified alias myalias in the SQL query but instead a default hibernate one col_1_0_

This seems to be a bug in Hibernate. Right?

Bruno


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:01 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I don't think Hibernate makes any promises to use the same aliases in the generated SQL as was used in HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:03 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
So how do I do to sort on myalias?

if I add the following order by clause at the end of the HQL: order by myalias


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:23 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I would expect Hibernate to keep track of the HQL<->SQL alias and use the proper alias in the SQL, but... maybe I am wrong. It seems like there are some limitations:

http://www.hibernate.org/hib_docs/v3/re ... l-ordering


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:27 am 
Beginner
Beginner

Joined: Mon Jan 31, 2005 11:04 am
Posts: 21
my workaround is to use order by col_1_0_ in the hql :-) what works fine
but i will not feel safe in production..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 8:30 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Yes, this seems a bit risky.


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

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.