-->
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: Set distinctResult = new HashSet(criteria.list());
PostPosted: Mon May 24, 2004 10:36 am 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
A question about the distinctResult that i have with:
Code:
Set distinctResult = new HashSet(criteria.list());

The order of the result (distinctResult) is not the order of the query because the Set is unsorted, it's correct?
How to maintei the order thet i define in the query?! Using TreeSet?

Gio


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 1:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
The problem is that TreeSet ordering is based on a Comparator. So you'd have to construct a Comparator that knows how to order the results in the manner in which they are ordered in the list.

The easier approach would be to create a new collection impl that functions as both a List and a Set at the same time. I have done this before and its pretty trivial. Basically, have the underlying storage be an ArrayList (to maintain the incoming order), however on add make sure that the given element does not yet exist in the underlying collection.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 6:19 pm 
Beginner
Beginner

Joined: Fri Oct 17, 2003 4:11 am
Posts: 40
Thanks!


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.