-->
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: need help with alias for expressions in hql queries
PostPosted: Thu Aug 18, 2011 1:29 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2010 4:32 pm
Posts: 22
my Hibernate version is 3.2.6.ga

Googling around reveals many people are having the same problems with Hibernate HQL not handling aliases very well. Apparently HQL only lets you alias a column that exists in a table. Also, HQL generates its own aliases for all columns in the query and these have the form col_x_y_. I've set my jdbc properties to show_sql=true to display the correct alias for the columns I wish to add,and tried these in my query, but even this doesn't work.

For my case I want to add two derived columns into a third derived column. Trivial in native SQL, surprisingly difficult in HQL.

My contrived, simplified example:
Code:
sqlcmd = " SELECT  aa.course.code, " +
         "        (CASE WHEN aa.gender = 'M' THEN 1 ELSE 0 END),  " +
         "        (CASE WHEN aa.gender = 'F' THEN 1 ELSE 0 END),  " +
         "        ( col_0_1_ + col_0_2_ ) " +
         "        FROM Student AS aa ";


How can I add the 2nd and 3rd columns together to form a 4th column in HQL?

TIA,

Still-learning Steve


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.