-->
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: many-to-many and ordering problem
PostPosted: Thu Jan 25, 2007 11:37 am 
Newbie

Joined: Thu Jan 25, 2007 11:27 am
Posts: 4
Hello

I have a many-to-many relationship via a join table.

let's they the represent books and authors.

when I have a book object and get all the authers with
book.getAuthors()
I want an ordered List. when using a Query I can call the list() method to
give me a List. but in the mapping file I have to use the <set> mapping (I couldn't get
an example using <list> to work. if this can be done let me know).

when I get the list from the database and put it into the authors property of the book
object I loose the ordering because this is a Set.
I can use a tree set and then I will have the ordering.

but let's say I want to order the authors on some specific criteria.
How can I do this ? can I store the ordering information in the join table in an extra column ?
that would probably work, but how do I access this column ?
or maybe I can insert them into a specific order into the join table and then retrieve them in
the same order.

I hope this is not to confusing. maybe I am just thinking to complicated.

any help appreciated.

best wishes

Claus


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 12:08 pm 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
I have successfully used the list for one-to-many association like this

<list name="childNodes" cascade="all" inverse="true">
<list-index column="LISTORDER"/>
<one-to-many class="childNodeClass"/>
</list>

I am not sure but I think this should work for many-to-many also.

else go through this link

http://www.hibernate.org/hib_docs/v3/re ... tions.html

it mentions that you can provide sort or order-by attributes in collection mapping to sort the collection elements.

Hope this help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 9:29 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
You can use list, but you can achieve the same with set also.

<set name="tags" table="PERSON_TAGS" order-by="lower(LANGUAGE) ASC" inverse="true">
<key column="PERSON_ID"/>
<many-to-many column="TAG_ID" class="xxx.Tag"/>
</set>

So here the set of tags will be ordered by column LANGUAGE.

Hope that helps.
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.