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.  [ 8 posts ] 
Author Message
 Post subject: order by and case insensitive
PostPosted: Tue Jan 20, 2004 7:36 pm 
Newbie

Joined: Mon Oct 06, 2003 2:20 pm
Posts: 10
I am using Oracle 8i
and using "order by c.fieldName ASC " in HQL


How can I construct the HQL query to get the sored result field (VARCHAR2) nnot case sensitive?

for example:
Currently it returns order like this: A,B,C,D,a,b,c,d

how can I get the result like A,a,B,b,C,c,D,d?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
try using "order by lower(c.fieldName) ASC" or whatever sql function Oracle uses for lowercase


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Its not HQL its the database. Try an SQL query in sqlplus to confirm.
You can choose to not use the order by clause and use Java to sort the result anyway you like.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 26, 2004 9:35 am 
Newbie

Joined: Thu Aug 26, 2004 9:21 am
Posts: 3
Hi,
By any chance we can sort the list in case insensitive without using HQL? Its just that we are using the paging functionality (setFirstResult+setmaxResults) as well. So, sorting at the java end is not possible.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 12, 2004 3:28 pm 
Newbie

Joined: Wed Sep 01, 2004 2:03 pm
Posts: 7
How do you accomplish case-insensitive ordering in the Criteria API?


Top
 Profile  
 
 Post subject: order by and case insensitive
PostPosted: Sun Nov 14, 2004 8:22 pm 
Newbie

Joined: Thu Aug 26, 2004 9:21 am
Posts: 3
Use the Expression.ilike() method.

For eg
Criteria crit = // Create a criteria obj
crit.add(Expression.ilike("username", anObj.getUsername(), matchMode));


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 2:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
pearljam118 wrote:
Hi,
By any chance we can sort the list in case insensitive without using HQL? Its just that we are using the paging functionality (setFirstResult+setmaxResults) as well. So, sorting at the java end is not possible.

Thanks.


The ordering clause as shown by Mike will order in the database. The HQL is being translated to SQL and executed at the database. Thus you will be fine with the paging.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 2:58 am 
Newbie

Joined: Thu Aug 26, 2004 9:21 am
Posts: 3
[quote="david"][quote="pearljam118"]Hi,
By any chance we can sort the list in case insensitive without using HQL? Its just that we are using the paging functionality (setFirstResult+setmaxResults) as well. So, sorting at the java end is not possible.

Thanks.[/quote]

The ordering clause as shown by Mike will order in the database. The HQL is being translated to SQL and executed at the database. Thus you will be fine with the paging.[/quote]


Thanks David,

I kinda work that one out :)

Just more info. I basically have a "PageCritieria" object takes in a page number (if applicable) which simply append the neccessary "criteria" to the Criteria or Query object. The object will also calculate the first and max result as well. It's essential 4 lines

int blockSize = getBlockSize() + 1; // Add the 1 for next block
int firstElement = calcStartingPageElementForBlock(); // Starts from 0 and not 1

// Now we can add the extra criteria for paging
aQuery.setMaxResults(blockSize);
aQuery.setFirstResult(firstElement);

At the moment, I have to pass the param to the "PageCriteria" object. What it would be "nice" is in the Query and Criteria object, it provide the methods for me (as a standardise method)! :P

I could've overloading the Query and Criteria object and called it "PJQuery" and "PJCriteria", but I chose not to... just in case a common functionality is available from Hibernate in the future. :)


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