Glad to hear that you worked through the problem. Thanks for letting us
know your solution.

Kevin


On Thu, Jan 9, 2014 at 5:05 AM, wlad <vvo...@yahoo.com> wrote:

> Yes, it does work, but with that query I am getting that extra data in
> result
> - number of comments. And I need to get result in a form of list of Post
> objects (List<Post>).
>
> In the meantime I have found a way to build this query using JPA Criteria
> API:
>
>         CriteriaBuilder cb = em.getCriteriaBuilder();
>         CriteriaQuery<Post> cq = cb.createQuery(Post.class);
>         Root<Post> p = cq.from(Post.class);
>         cq.select(p);
>
> cq.orderBy(cb.desc(cb.size(p.<Collection<Comment>>get("comments"))));
>
>         Query q = em.createQuery(cq);
>         List<Post> resultList = (List<Post>) q.getResultList();
>
> Anyway, thanks for reply.
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/JPA-Criteria-API-query-sorting-by-number-of-elements-in-collection-tp7585829p7585832.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Reply via email to