openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wlad <vvo...@yahoo.com>
Subject Re: JPA Criteria API query - sorting by number of elements in collection
Date Thu, 09 Jan 2014 11:05:54 GMT
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&lt;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.

Mime
View raw message