how to order by subquery with jpa criteria query api

I am using java jpa criteria query for doing something like this:

    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<DTO> criteria = builder.createQuery(DTO.class);

    //from
    Root<A> root = criteria.from(A.class);

    //where
    //set predicates...

    //sub query
    Subquery<Long> subQuery = criteria.subquery(Long.class);
    Root<B> subRoot = subQuery.from(B.class);        
    subQuery.select(builder.count(subRoot));

    //select
    criteria.multiselect(
            A.field1,
            A.fidld2,
            subQuery.getSelection()
    );

    //order by:=====error here!
    criteria.orderBy(builder.desc(subQuery));
    //or = > orderBy subQuery.getSelection();

and it throw exception:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException:unexpected AST node

How can I do it correctly?