-->
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.  [ 4 posts ] 
Author Message
 Post subject: many-to-many with ISet: Correct order?
PostPosted: Wed Mar 22, 2006 7:12 pm 
Newbie

Joined: Mon Jan 30, 2006 6:33 pm
Posts: 9
Hi,
I have a many-to-many relation with 3 tables (quite common). Everything works great. In the mapping file I specify this as a Set and therefore my class uses the Iesi ISet interface.
I am iterating through the elements of this set and building a table on a web page. The table contains a row for each element. But sometimes element A is before element B and vice versa.
This is a really annoying behaviour and I know that the reason for this is the ISet.
How can I assure a non-changing order of my elements?
I really like to use a Set and not a Bag.
Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 9:50 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
A set by definition does not define a specific order, however you may use the sort or order-by attributes in the <set> element in your mapping file to specify a specific sort order.

Alternatively you could use a list mapping, but that would involve adding a "position" column in your join table and chaing your ISet interface to IList.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 6:29 am 
Newbie

Joined: Mon Jan 30, 2006 6:33 pm
Posts: 9
Using a "order-by" in my mapping file helped to have a non-changing sort order.
I am wondering why the sort order is changing anyway? I am not modifying my elements. What makes the ISet return my elements in a different order if the circumstances are the same? It's kind of non-deterministic.
Thanks so far!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 3:47 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
theblob wrote:
I am wondering why the sort order is changing anyway?

Because by definition relations (tables) are unordered sets of rows. Since they aren't required to, almost no RDBMS that I know of makes any guarantee about the ordering of rows returned to an unordered query, even sequential calls of the same query.
Quote:
It's kind of non-deterministic.

It's probably deterministic on some level, but not one readily visible to you or me.

As a side note, I've also used "order-by" to great effect. Quite handy. I have never used "sort", however. Just seems easier to let the database do the work whenever possible.


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