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.  [ 2 posts ] 
Author Message
 Post subject: Sort a many-to-many collection
PostPosted: Mon Dec 04, 2006 10:16 am 
Beginner
Beginner

Joined: Tue May 17, 2005 2:48 pm
Posts: 47
Hibernate version:

NHibernate 1.2.0

Mapping documents:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="App.Core" namespace="App.Core.Domain">
<class name="Teacher" table="Teacher">
<id name="Id" column="TeacherId">
<generator class="identity" />
</id>
...
<bag name="Subjects" access="nosetter.camelcase-underscore" table="TeacherSubject" cascade="all">
<key column="TeacherId" />
<many-to-many class="Subject" column="SubjectId"/>
</bag>
</class>
</hibernate-mapping>


I have a many-to-many association: Teacher <--> Subject. A teacher can give multiple subjects; A subject can be given by multiple teachers.

How can I sort the Subjects collection of the Teacher class by the name of the subject? I already tried the 'order-by' element in the bag node. This doesn't work because this order applies to the TeacherSubject table and not to the Subject table.

Thanx in advance,
Jack


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 4:05 am 
Newbie

Joined: Thu Jun 22, 2006 4:04 am
Posts: 8
Location: Prague
This is limitation of NHibernate and is not supported even by Hibernate. Quite common request on forum, hoverer i didn't found any explanation why this is not implemented...
Write comparator for your Subject class and use sort attribute on the collection.
Look here and here for more details...

Liwoj


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