-->
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: Ordering with Association-Tables
PostPosted: Wed Mar 15, 2006 2:43 pm 
Newbie

Joined: Wed Mar 15, 2006 2:25 pm
Posts: 4
Hi all,
i'm sitting here on a pretty weird problem and could need some help or ideas. I have two model classes (Course and Participants) and one association class (takes_part) for storing many-to-many links with additional attributes. The structure is as follows:

Course --- many-to-one ---> takes_part <--- many-to-one --- Participants

Now it is that i need to get the participants of a course and the other way round, the courses of a participant. Currently i have a hibernate.set in both Course and Participant pointing at takes_part:
Code:
...
  /**
   * @hibernate.set inverse="true" group-by="WITH THAT I CAN ONLY ORDER BY KEYS IN THE ASSOCIATION-TABLE"
   * @hibernate.collection-key ...
   * @hibernate.collection-many-to-one class="TakesPart"
...


The problem is that i would like to order this set by the other end. E.g. when retrieving the participants of a course i'd like to order them by there names. Currently i can only order the collection by keys that are available directly in the association class takes_part, but not by a key in the other class. (I hope i explained this well enough. As you might have noticed, i'm not a native speaker.. ;-)

I've already looked at composite-elements, but they are pretty unintuitive and if i got the docs right, they are not bi-directional.

Is there an elegant way to order the contents of this set? In raw SQL this would be quite easy:
Code:
select * from Course as c, takes_part as t, Participant as p where c.id = SOMEID and t.course_id = c.id and p.id = t.person_id order by p.name


Btw. i'm using Hibernate 3.1 with a MySql server.

Many thanks in advance. :-D

_________________
Cheers,
Jakob


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.