-->
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: HQL query sorted by a computed value
PostPosted: Tue Sep 01, 2009 12:05 pm 
Newbie

Joined: Tue Sep 01, 2009 11:53 am
Posts: 1
I've been having difficulty coming up with an HQL query the does something which seems like it should be very simple.

I need to select a value based on whether or not it is null. For example, let's say I have a table with userrating and overrideRating columns, where overrideRating may (and in most cases is) null.

I want overrideRating to override userrating, and sort by that value. I was able to do this in SQL as follows:
Code:
SELECT IF (overriderating is not null, overriderating, userrating) as rating
FROM myobjects
ORDER BY rating desc

How would I express this in HQL? I don't need to have my hibernate properties mapped to this computed value. I just want to sort by this computed value.


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.