MetadataStatusSpecs { public static Specification<MetadataStatus> hasUserId(final int userId) { return new Specification<MetadataStatus>() { @Override public Predicate toPredicate(Root<MetadataStatus> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Integer> userIdAttributePath = root.get(MetadataStatus_.id).get(MetadataStatusId_.userId); Predicate uuidEqualPredicate = cb.equal(userIdAttributePath, cb.literal(userId)); return uuidEqualPredicate; } }; } private  MetadataStatusSpecs(); static Specification<MetadataStatus> hasMetadataId(final int metadataId); static Specification<MetadataStatus> hasUserId(final int userId); static Specification<MetadataStatus> hasUserIdMetadataIdAndStatusId(final int userId, final int metadataId,
                                                                               final int statusId);  }
@Test public void testHasUserId() throws Exception { MetadataStatus md1 = _repo.save(newMetadataStatus()); _repo.save(newMetadataStatus()); final List<MetadataStatus> found = _repo.findAll(hasUserId(md1.getId().getUserId())); assertEquals(1, found.size()); assertEquals(md1.getId(), found.get(0).getId()); }