-->
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: Can hibernate order queries by the alias?
PostPosted: Thu Jan 28, 2010 6:00 pm 
Beginner
Beginner

Joined: Wed Jul 30, 2008 8:43 am
Posts: 32
Hi.

Currently I need to do the ordering on the subquery like this:

Code:
select ord, (select sum(pays.income) from ord.payments pays) as sumIncome from Order as ord order by sumIncome


This looks pretty simple, but hibernate fails to parse the query as the sumIncome column is not found. The workaround I found is putting the generated name of the subquery result to the order by clause (pay attention to the last col_1_0_ alias):


Code:
select ord, (select sum(pays.income) from ord.payments pays) as sumIncome from Order as ord order by col_1_0_


Strange, but this works! Although, I don't like such code and don't want to rely on the generated aliases.

Any thoughts?


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.