-->
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.  [ 1 post ] 
Author Message
 Post subject: Many-to-Many Ordered Set
PostPosted: Wed Sep 20, 2006 10:47 am 
Newbie

Joined: Wed Sep 20, 2006 10:33 am
Posts: 1
I have the following mapping:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="MyData.Department, MyData" table="departments">

    <id name="Id" column="id" type="integer">
      <generator class="increment" />
    </id>
    <property name="Name" column="name"></property>
   
    <set name="People" table="department_people" lazy="true">
      <key column="department_id"/>
      <many-to-many class="MyData.Person, MyData" column="person_id" />
    </set>   
  </class>
</hibernate-mapping>


I would to simply have code that looks like:

Code:
foreach (Person person in mydept.People)
{
    Console.WriteLine(person.Name);
}


and have the list of people come out in alphabetical order.

I was wondering what the best option for this is. So far I thought of the following.

1) order-by - Unless I'm mistaken, this doesn't work since the name column isn't in the department_people table. Instead of department_people I could create a view which is the department_people table with the person's name as another column. So I can order-by the name. So far this is a read-only project so I'm not familiar enough with NHibernate to determine how this might negatively impact saving.

2) Adding another property to my Department class which sorts and returns a new ISet of people.

3) HQL query - I don't have the joining table (department_people) in hibernate so I don't know how I can join this.

Thanks,
Andy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.