-->
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: Order results by property of another table
PostPosted: Tue Apr 23, 2013 7:02 am 
Newbie

Joined: Tue Apr 23, 2013 6:58 am
Posts: 2
I have TopicEntity which contains many PostEntity. Each PostEntity belongs to exactly one TopicEntity. I need to sort topics by the last post creation date, that is the creationDate property of the newest post in the topic.

The following code works if there is only 1 post in each topic:

Code:
this.session.createCriteria(TopicEntity.class, "topic")
    .createAlias("topic.posts", "post", CriteriaSpecification.LEFT_JOIN)
    .addOrder(Order.asc("post.creationDate")).list();


When there are more posts in a topic, the topic is sorter according to the FIRST post.

To sort by the NEWEST post in the topic I think need to somehow first sort the posts in descending order of date and THEN use that list to sort the topics, if that makes any sense...

Any help would be greatly appreciated :).


Top
 Profile  
 
 Post subject: Re: Order results by property of another table
PostPosted: Tue May 07, 2013 1:15 pm 
Newbie

Joined: Tue Apr 23, 2013 6:58 am
Posts: 2
Bump, still looking for solution.


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.