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 :).