UserSpecs { public static Specification<User> hasAuthType(final String authType) { return new Specification<User>() { @Override public Predicate toPredicate(Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<String> authTypeAttributePath = root.get(User_.security).get(UserSecurity_.authType); Predicate userIdEqualPredicate = cb.equal(authTypeAttributePath, authType); return userIdEqualPredicate; } }; } private  UserSpecs(); static Specification<User> hasUserId(final int userId); static Specification<User> hasProfile(final Profile profile); static Specification<User> hasUserName(final String userName); static Specification<User> hasEmail(final String email); static Specification<User> hasNullAuthType(); static Specification<User> hasAuthType(final String authType); static Specification<User> userIsNameNotOneOf(final Collection<String> usernames); static Specification<User> hasUserIdIn(final Collection<Integer> ids); static Specification<User> hasEnabled(final Boolean enabled); static Specification<User> loginDateBetweenAndByGroups(final ISODate loginDateFrom,
                                                                  final ISODate loginDateTo,
                                                                  final Collection<Integer> groups);  }
@Test public void testHasAuthType() throws Exception { User user1 = _userRepo.save(newUser(_inc)); String expectedType = "expected"; user1.getSecurity().setAuthType(expectedType); final User user2 = newUser(_inc); user2.getSecurity().setAuthType("authtype"); _userRepo.save(user2); final List<User> found = _userRepo.findAll(hasAuthType(expectedType)); assertEquals(1, found.size()); assertEquals(user1.getId(), found.get(0).getId()); }