I have many Topic objects and each Topic hasMany posts:Post How can I order all Topic objects based on their posts count??
相关问题
- Grails External Configuration. Can't access to
- grails unit test + Thread
- Does the multiple datasource feature of Grails 2.0
- JMS Job queue with Grails
- Grails: SpringSecurity roleHierarchy not working a
相关文章
- Grails: How to make everything I create Upper Case
- What does mean Hibernate's “unsaved-value mapp
- Grails and Quartz: Bad value for type long
- Sending JSON to javascript on GSP
- Grails application is not found after updating to
- How to save to a file system directory in Grails
- Groovy can't compile the code from a solution
- Grails: what are the main issues (and his solution
You can do it, but it requires two queries. This is because to order by the size of a collection, you need to use a 'group by' but this requires that you enumerate all of your Topic properties. If you add or remove one the query will break. So the solution is to run one query that finds ordered ids, and a second that gets the instances for those ids:
You can do it in one HQL query with size() function. This way you get Topic instances in one query:
I've found this on http://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html, section 14.16 Tips & Tricks.