I am using JPA, MySQL.
There are following entities:
Then, there is a method in PostDAOBean:
Now,you can see that named query used in this method is SELECT p FROM Post p ORDER BY SIZE(p.comments) DESC.
And this is wrong, because function SIZE(some_collection) cannot be used to be ordered by it in JPQL.
I would like to get all posts from database ordered by number of comments.
How should JPQL query look then?
posted 6 years ago
I found out that another way to get all posts from database ordered by number of comments is by using JPA Criteria API.
This is what I am trying now:
I am aware I am missing getting the size of the set comments, but don't know how to add that part. Need help with Criteria API.