CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(clazz);
Root<T> root = cq.from(clazz);
ManagedType<T> mt = em.getMetamodel().managedType(clazz);
SortOrder sortOrder = query.getSortOrder();
if (sortOrder != null && !sortOrder.isEmpty()) {
// Iterator<Entry<String, Direction>> iter = sortOrder.iterator();
Iterator<SortOrderItem> iter = sortOrder.iterator();
List<Order> orderList = new ArrayList<Order>();
while (iter.hasNext()) {
// Entry<String, Direction> entry = iter.next();
// Path<?> path =
// root.get(mt.getSingularAttribute(entry.getKey()));