-->
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: Advice pls :order-by for other end of one-to-one association
PostPosted: Thu May 04, 2006 4:14 am 
Newbie

Joined: Fri Apr 28, 2006 1:09 pm
Posts: 9
I'm trying to find the "cleanest" way of sorting by the other end of a one to one association. What I have so far is as follows;

User -(one-to-many)->subscription-(one-to-one)->feedDetails

What I would like to do is get all of the subscription objects for a user sorted by the title field of feedDetails.

In JDBC Prepared statement terms it would be something like;

Code:
select      s.*

from      subscriptions s, feeddetails f

where      s.user_id = ?
and      s.feed_id = f.feed_id

order by      f.title


Is there a way to map this into the order-by attribute of a collection in a mapping file?, or should I just use the SQL and a SQLQuery object?


Hibernate version:

3.1.2

Mapping documents:

Under construction

Code between sessionFactory.openSession() and session.close():

Name and version of the database you are using:

MySQL 3.2.3


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 12:21 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I'm pretty sure that it's not possible to do that in the mapping file, unless you switch from using <one-to-one> to using <join>. However, it's perfectly feasible to have your Subscription class implement the Comparable interface and for compareTo to use getFeedDetails().getTitle() to sort. Then just use sort="natural" on the set in the User mapping.

You can use Comparator and put the sort code in a different class, if you like. Then use sort="ComparatorClassName" on the set.

_________________
Code tags are your friend. Know them and use them.


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.