I have an Entity with a List<EntityRevision>
contained in it. The collection has an @OrderColumn
.
I'd like to get all the EntityRevisions
for an Entity ordered by their index.
I can do this with the following query:
SELECT er
FROM Entity e JOIN e.revisions er
WHERE e.id = :entityId
ORDER BY index(er)
But I can't figure out how to do this with the CriteriaQuery
.
Using EclipseLink 2.3.2 / JPA 2.0.3 - the Root<EntityRevision>
has no index()
method on it that I can use in the orderBy.
Any ideas?
I have not tested it, but something like criteriaQuery.orderBy(criteriaBuilder.asc( ((ListJoin)root.get("listMapping")).index())); should work if your listMapping is a list with an orderby column.