-->
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: Sort options for one-to-many
PostPosted: Mon Oct 06, 2003 4:55 pm 
Newbie

Joined: Mon Oct 06, 2003 4:41 pm
Posts: 18
Firstly my apologies if I should have been able to work this out from the documentation but I've been staring at the problem with no progress too long so I'd appreciate any help.

I have a simple one-to-many relationship and I have two requirements:

1. That the getter for the many side returns the results in a particular order. This I can do with a <set sort="myCustomComparator">.

2. That I can get the index of the child in it's collection. This I can do with <list><index column="index"></list>.

However I really want to combine the two requirements. I.e. I want Hibernate to order my children by the custom comparator and write the correct values to an index field in the table so that I can retrieve the index with a child.getIndex() option method call.

I assume this isn't really what the various one-to-many collection options are all about but could anyone suggest the best way to do it? Should I use callbacks to write the index value of the list onSave()?

Thanks,
Matt.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 7:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Hibernate appropriately sets the index value for list elements based on their position within the List (a List be definition is ordered). So when persisting the many side of the association, just make sure the List is sorted based upon your comparison requirements.

Then, when you hydrate the object graph to include this List, Hibernate will make sure the list elements are ordered by the index property.

So based on what you said, it seems like just an additional step prior to persisting the owner of the List association to make sure it is appropriately sorted.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2003 2:51 pm 
Newbie

Joined: Mon Oct 06, 2003 4:41 pm
Posts: 18
Thanks, that cleared up my confusion and all is fixed now.

Matt.


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.