-->
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: left join fetch. How do you order the collection fetched?
PostPosted: Thu Mar 26, 2009 2:55 am 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
I am using a left join fetch in the following JPQL:
Code:
select distinct q from Question q
          left join fetch q.responses
         where q.user.username = :uName
          and q.type = :qType
         order by q.created desc


Is there a way that I can also sort the collection (q.responses) in this query?

I.E. Imagine the collection contains RESPONSE entities that have a date field called createDate. I would like to do an order by response.createDate.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 26, 2009 3:45 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
There is an order-by field for the <set>, <map> etc mappings. You can use that. For eg:
Code:
      <set name="responses" table="responses" cascade="all-delete-orphan" order-by="createDate">
         <key column="QUE_ID" />
         <one-to-many class="Response" />
      </set>

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 26, 2009 4:22 pm 
Beginner
Beginner

Joined: Sat Feb 07, 2009 4:08 pm
Posts: 22
Location: New York City
Thank you. That was exactly what I was looking for. I ended up using the Annotation:

@OrderBy("created DESC")

Regards,
John


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