-->
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.  [ 5 posts ] 
Author Message
 Post subject: Which collection type for sorted collection?
PostPosted: Fri Mar 26, 2004 2:34 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:06 pm
Posts: 26
Location: Tampa, FL
A colleague and I are going round and round on trying to figure out which Hibernate collection type will best fit our need for an ordered collection that does NOT have a good candidate column for an index. We have several scenarios where the collections in question use either dates or strings or large integer numbers (abstract keys) to determine their collections's ordering.

Which of the Hibernate collection types (List, Set, Map, Bag) best fit the need for a collection that will return a guaranteed order on interation over the collection?

I have currently settled on using a set with an order-by tag to set the order. I'm not sure that this will guarantee the order of iteration however. My colleague is suggesting that a Bag will maintain order without the need for an explicit "hibernate" index tag.

Can someone clarify this?

Thanks for any help. Using Hibernate 2.1.2 on Oracle 9.2.

_________________
Bill Pfeiffer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 3:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I'm not sure that this will guarantee the order of iteration however.


What do you mean by this??


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 27, 2004 5:36 pm 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:06 pm
Posts: 26
Location: Tampa, FL
gavin wrote:
What do you mean by this??


I'm not sure that a Set will guarantee a specified order when using the iterator returned from a Hibernate created Set, even though I've specified an "order-by" tag in hibernate.

Overall my general question is what hibernate collection type is the best fit for a list of ordered objects that don't have a good candidate "index" column as required by the Hibernate List type.

Sorry if I'm not being clear but I'm still learning the Hibernate ins and outs.

Thanks for any help

_________________
Bill Pfeiffer


Top
 Profile  
 
 Post subject: Section 6.6, 6.7 of the reference answered my question.
PostPosted: Tue Mar 30, 2004 12:01 am 
Beginner
Beginner

Joined: Mon Feb 09, 2004 3:06 pm
Posts: 26
Location: Tampa, FL
Section 6.6, 6.7 of the reference answered my question.

_________________
Bill Pfeiffer


Top
 Profile  
 
 Post subject: How is the TreeSet without implementing Comparable working?
PostPosted: Fri Jun 05, 2009 11:13 am 
Regular
Regular

Joined: Tue Feb 19, 2008 6:05 pm
Posts: 82
Code:
               
                <set name="children" order-by="child_id desc" cascade="none" inverse="true">
         <key column="parent_id" ></key>
         <one-to-many class="Child"/>
      </set>

           private Set<Child> children = new TreeSet<Child>();


A query

Code:
from Parent parent left join fetch parent.children

brings the children in the right order

Interestingly, without the Child object being implementing comparable or any thing I am able to get the set in the correct order I wanted.

After testing many times, but how is this possible and why am I getting the set in the right order I wanted from a set???

I know that I just cannot add to a TreeSet without the class implementing comparable but not only am I able to add to my TreeSet but also get the set elements in the right order??


Code:
select parent.parent_id, child.child_id from Parent left join children child
order by child_id asc

also brings the children in ascending order


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