UserGroupSpecs { public static Specification<UserGroup> hasGroupId(final int groupId) { return new Specification<UserGroup>() { @Override public Predicate toPredicate(Root<UserGroup> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Integer> grpIdAttributePath = root.get(UserGroup_.id).get(UserGroupId_.groupId); Predicate grpIdEqualPredicate = cb.equal(grpIdAttributePath, cb.literal(groupId)); return grpIdEqualPredicate; } }; } private  UserGroupSpecs(); static Specification<UserGroup> hasGroupId(final int groupId); static Specification<UserGroup> hasGroupIds(final List<Integer> groupId); static Specification<UserGroup> hasUserId(final int userId); static Specification<UserGroup> hasProfile(final Profile profile); static Specification<UserGroup> isReservedGroup(final boolean isReservedGroup);  }
@Test public void testHasGroupId() throws Exception { UserGroup ug1 = _repo.save(newUserGroup()); _repo.save(newUserGroup()); _repo.save(newUserGroup()); _repo.save(newUserGroup()); UserGroup found = _repo.findOne(hasGroupId(ug1.getId().getGroupId())); assertEquals(ug1.getId(), found.getId()); }