List<Monitoring> monitoringList = repository.findAll((root, query, cb) -> { List<Predicate> list = new ArrayList<>(); list.add(cb.equal(root.get("projectId").as(String.class), projectId)); Predicate[] p = new Predicate[list.size()]; query.where(cb.and(list.toArray(p))); query.orderBy(cb.asc(root.get("cameraOrder"))); return query.getRestriction(); });