-->
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: Mon Sep 26, 2005 6:01 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: Mon Sep 26, 2005 10:38 pm 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
To sort the collection on a retrieved object you have a couple of options.

One option is to have the collection retrieved come back from the database in a particular order : order-by in the mapping or a filter

Another option is to have some programmatic sorting capability through a comparator.

------

You should look at Hibernate 3.0.5 documentation section 7.3.2 if you want a bidirectional many-to-many or 7.2.4 otherwise.

First, I notice you mention a class plus a package in the <many-to-many class="...,...".... I doubt this is legal.

Next, why are you using "client_name" in the order by if you want to order by the organization name?


Joe

_________________
Joe W


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.