1 2 3 4 5 6 7 8 9 10 11 12 13 14
| @Override public List<String> findAllByUserAndStatusAndDepartmentIn(User user, String key, Department department) { CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); CriteriaQuery<String> query = criteriaBuilder.createQuery(String.class); Root<User> root = query.from(User.class); query.select(root.get("id")); Join<User,Department> join = root.join("departments", JoinType.LEFT); query.orderBy(criteriaBuilder.desc(root.get("createdDate"))); Predicate restrictions = criteriaBuilder.conjunction(); restrictions = criteriaBuilder.and(join.get("id").in(department.getId())); query.where(restrictions); List<String> result = entityManager.createQuery(query).getResultList(); return result; }
|