-->
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.  [ 2 posts ] 
Author Message
 Post subject: using "case when" structures hql
PostPosted: Thu Aug 07, 2008 6:11 am 
Newbie

Joined: Thu Nov 04, 2004 4:07 am
Posts: 2
Location: Amsterdam
Hi,

I'm using hibernate 3.2.5 and I would like some advice on the following use case: I want to order a query based on "is null" of some columns, 2 columns is null gives an earlier occurence than 2 columns not null.
In oracle 10.? I can do:
Code:
select *
from   ( select  *
         from    tbl_eqi eqi
         order by case when pos_ben is null and MAR_BEN is null then 0
                when POS_BEN is null and MAR_BEN  is not null then 1
                when POS_BEN is not null and MAR_BEN  is null then 2
                when POS_BEN is not null and MAR_BEN  is not null then 3
           end
      )


Is there an equivalent in HQL or should i use native sql or some java manipulation?

regards,
Jeroen.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 07, 2008 1:51 pm 
Newbie

Joined: Mon Aug 15, 2005 2:00 pm
Posts: 19
Yes, HQL supports both simple and searched CASE expressions (http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html, see section 14.10). The syntax should be all the same as in your Oracle example, except for entity/property names instead of DB tables/fields.

HTH,

Alex


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.