-->
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: URGENT........Sorting results when using load
PostPosted: Mon Jun 13, 2005 11:03 am 
Hello all

I have a question..

Lets say I have two tables Department and Professor

The department table has id(primary key), name
Professor table has id(primarykey), name,address

The Dept_Prof table has deptid and profid.

the corresponding entities are defined in C# and also the mapping is done correctly
class Department
{
int id;
string name;
IDictionary Professors;

}

class Professor
{
int id;
string name;

IDictionary Departments;
}


getProfessorsByDept(int id) is a method to find professors who teach a particular dept.


IDictionary getProfessorsByDept(int id)
{
Department dept = session.Load(
typeof(Department), id );
return dept.Professors;
}

Now how do I modify the above method to sort the results by Name..


Please suggest
Thanks
Sekhar


Top
  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 2:29 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
I don't think it is possible in your specific instance. You _could_ use an orderby attribute in the Department.Professors collection mapping, but I am guessing you only have DepartmentID and ProfessorID in that association table. Ordering by one of those wouldn't give you rhe orderby you are looking for.

Your best bet is to introduce a business method in your DAO, or service layer and use the ICriteria interface.

Alternately, you could implement IComparable on the Professor object and then .Sort() the arraylist, but I've never done that with an IDictionary and I don't know if that is possible.

my .02.

-devon


Top
 Profile  
 
 Post subject: Session.Find
PostPosted: Wed Jun 15, 2005 11:00 am 
Hi,
Why don't u try the method Find.
IList List = Session.Find(YourQuery) ;
Here u can use the query that u want to recover the corresponding Professors List.

Regards


Top
  
 
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.