-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate 2.1 ORDER BY with JDK1.3.X
PostPosted: Wed Dec 17, 2003 12:51 am 
Newbie

Joined: Wed Dec 17, 2003 12:13 am
Posts: 4
In the latest 2.1 documentation, I read that JDK1.4 is necessary for the ORDER BY clause to be used in an HQL query. I do not have the luxury of using JDK1.4 because my application server does not support it. I would like to use Hibernate as my persistence mechanism but I MUST HAVE ORDER BY for my queries. Is it in any way possible to use JDK 1.3 and still have order by? Could a Commons Collection class such as SequenceHashMap be used to store the values of the queries in order to maintain the order of insertion. If extend HashMap or HashSet to maintain the order of insertion, can I force hibernate to use those implementations instead?

Thanks,
J2eeguru


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 1:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Read more carefully. It says nothing about HQL queries.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 10:40 am 
Newbie

Joined: Wed Dec 17, 2003 12:13 am
Posts: 4
Are you saying it is possible to use JDK1.3 and still take advantage of the ORDER BY clause?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 2:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes in HQL you can

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 3:17 pm 
Newbie

Joined: Wed Dec 17, 2003 12:13 am
Posts: 4
Section 6.7 states If you want the database itself to order the collection elements use the order-by attribute of set, bag or map mappings. This solution is only available under JDK1.4 or higher(it is implemented using LinkedHashSet or LinkedHashMap). This performs the ordering in the SQL query, not in memory.

JDK 1.3 does not support have LinkedHashSet or LinkedHashMap. It seems that I would get some kind of exceptions if I were to do an ORDER BY while using JDK1.3.

I am in the process of determining the persistence mechanism for my application and Hibernate is a strong candidate. I would likely use Hibernate as the implementation of my DAOs behind stateless session bean.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 8:37 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Look, there are two different things:

1. order-by attribute of collection element which defines default order in which Hibernate loads collection items
2. ORDER BY clause of HQL/SQL

JDK 1.4 is required for the first one (attribute). ORDER BY clause in HQL works regardless of JDK used so you can always write

Code:
sortedUsers = s.filter( group.getUsers(), "order by this.name" );


This example is from doc "5.7. Other Ways To Sort a Collection".

Also if you need sorted collection just for output, you can let Hibernte load collection as it wants and then create new collection sorted with any comparator you like.


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