-->
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: addOrder with Symbols!
PostPosted: Tue Dec 19, 2006 12:26 pm 
Newbie

Joined: Tue Dec 19, 2006 12:00 pm
Posts: 1
Hibernate version: 3.0

Database: Oracle 9i

My problems relates to ordering results from a Hibernate query. I am using the following line of code to return all records from a specific database table:

HibernateUtil.getSession().createCriteria(clazz).addOrder(Order.asc("description")).list();

...where 'clazz' is a mapped POJO.

On first inspection, everything seems fine. My results are ordered firstly alphanumerically, then alphabetically, i.e.

1
2
9
A
B
C
Z

and so on. The "problem" occurs when I retrieve records that contain symbols as their description. I was hoping that such records would appear at the beginning of my retrieved records, and indeed that is the case for the majority of symbols, i.e.

"
$
%
1
2
9
A
B
C
Z

However, for some reason, certain symbols are appearing at the END of my results. So my list of results looks something like this...

"
$
%
1
2
9
A
B
C
Z
/
£

Does anyone know why my ordering is returning symbols such as $ and % at the start of my list of results, while symbols like / and £ appear at the end of my list of results? Is is possible to specify how symbols are ordered using Hibernate???

Apologies if the above makes no sense whatsoever.


Top
 Profile  
 
 Post subject: Re: addOrder with Symbols!
PostPosted: Tue Dec 19, 2006 3:35 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
jamesyreid wrote:
However, for some reason, certain symbols are appearing at the END of my results. So my list of results looks something like this...

"
$
%
1
2
9
A
B
C
Z
/
£
Does anyone know why my ordering is returning symbols such as $ and % at the start of my list of results, while symbols like / and £ appear at the end of my list of results?

I think this is not an Hibernate issue, if to be considered as an issue. You should use the SQL logged in your console to test it under SQLPlus or any other SQL Client. I guess you'll have the same order as you saw.

When you put addOrder() like you did, you just ask Hibernate to add an "order by" clause to the generated SQL Query, then Hibernate processes the answer in the order it comes back.

So, the order you're finding quite abnormal is certainly the default one for Oracle, that's all :-).

jamesyreid wrote:
Is is possible to specify how symbols are ordered using Hibernate???

I don't if it's possible with Hibernate, but you could write a simple Java comparator that would do the sorting you want on the retrieved list. Something like :

Code:
Query q = session.createQuery(...);
List result = Collections.sort(q.list(), new YourComparator());

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.