-->
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.  [ 3 posts ] 
Author Message
 Post subject: help with advanced ordering
PostPosted: Thu Jun 22, 2006 3:48 am 
Newbie

Joined: Wed Feb 01, 2006 10:33 am
Posts: 15
Hibernate version:3.2.RC2

I have ordered all my activities on description .

Every activity has a percentcompleted intvalue from 0 to 100.
I want to order by 100% completed then by 0 to 99.

So that all activities that are finished will display at the bottom of the list.

How would I create a query that accomplishes this?

This is my simplified query that I'm basing the sort on:
Code:
List Activities = session.createCriteria(Activity.class)
                   .addOrder(Order.asc("description")   )
                   .list()


Thanks in advance for any help


Top
 Profile  
 
 Post subject: Re: help with advanced ordering
PostPosted: Thu Jun 22, 2006 3:53 pm 
Beginner
Beginner

Joined: Fri Jun 02, 2006 1:14 am
Posts: 30
I'm not sure how to do it in Hibernate using the Criterion API, but you can use a "CASE" expression in SQL to achieve this effect. The syntax for it differs between databases, here's how Postgres does it:

http://www.postgresql.org/docs/7.4/stat ... l#AEN11384

According to the Hibernate manual, Hibernate supports the "CASE" construct in HQL:

http://www.hibernate.org/hib_docs/v3/re ... xpressions

But I've never used it myself, so I don't know how well it works.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 2:34 am 
Newbie

Joined: Wed Feb 01, 2006 10:33 am
Posts: 15
Can you try to give an example?

if I use Case in the where clause i get another variable.

and i only want to get the activity objects, and order them by the case..

This is what i want it to do in pseudo code

order by percentCompleted asc where percentCompleted == 100

returns a list:
Code:
Name                      percentCompleted
Activity2                         99%
Activity4                         20%
Activity5                          4%
Activity6                         54%
Activity1                        100%
Activity3                        100%



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