To clarify:
When doing substring without a length parameter, the error happens (seen below). If you specify a length with a literal start, it works.
query.orderBy(cb.desc(cb.substring(orderPath, cb.literal(2))));
Additionally if one of the arguments to the substring call is a function call that takes parameters, it seems the argument list isn't passed properly:
query.orderBy(cb.desc(cb.substring(orderPath, cb.function("PATINDEX", Integer.class, cb.literal("%[0-9]%"), orderPath), cb.length(orderPath))));
This renders:
substring(purchaseor0_.PO_NUMBER, PATINDEX(?, purchaseor0_.PO_NUMBER))