-->
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: Sorting a many-to-many collection
PostPosted: Thu Sep 22, 2005 2:07 pm 
Beginner
Beginner

Joined: Mon Sep 26, 2005 5:57 pm
Posts: 39
I have a many to many collection like so:

<bag name="organizations" table="claim_user_orgs" lazy="true" >
<key column="claim_user_id" />
<many-to-many class="CID.IPath.NewBusinessLayer.organization, CID.IPath.NewBusinessLayer" column="organization_id" />
</bag>

where claim_user_orgs is an association table, and just has 2 columns: claim_user_id and organization_id.

I want the collection property "organizations" of the claim_user object to return the list of organizations sorted by organization_name, so I did this:

<bag name="organizations" table="claim_user_orgs" lazy="true" order-by="client_name asc" >
<key column="claim_user_id" />
<many-to-many class="CID.IPath.NewBusinessLayer.organization, CID.IPath.NewBusinessLayer" column="organization_id" />
</bag>

However, this gives me an error, because there is no column called client_name in the association table.

How can I sort a many-to-many collection? And where would I put the order-by clause?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 6:21 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
One solution documented in the Hibernate documentation is to sort them at runtime:
Quote:
Associations may even be sorted by some arbitrary criteria at runtime using a filter().

sortedUsers = s.filter( group.getUsers(), "order by this.name" );


Regards,
Radu


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.