UserGroupSpecs { public static Specification<UserGroup> hasUserId(final int userId) { return new Specification<UserGroup>() { @Override public Predicate toPredicate(Root<UserGroup> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Integer> userIdAttributePath = root.get(UserGroup_.id).get(UserGroupId_.userId); Predicate userIdEqualPredicate = cb.equal(userIdAttributePath, cb.literal(userId)); return userIdEqualPredicate; } }; } 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 testHasUserId() throws Exception { UserGroup ug1 = _repo.save(newUserGroup()); _repo.save(newUserGroup()); _repo.save(newUserGroup()); _repo.save(newUserGroup()); UserGroup found = _repo.findOne(hasUserId(ug1.getId().getUserId())); assertEquals(ug1.getId(), found.getId()); }