MetadataValidationSpecs { public static Specification<MetadataValidation> hasMetadataId(final int metadataId) { return new Specification<MetadataValidation>() { @Override public Predicate toPredicate(Root<MetadataValidation> root, CriteriaQuery<?> query, CriteriaBuilder cb) { Path<Integer> metadataIdAttributePath = root.get(MetadataValidation_.id).get(MetadataValidationId_.metadataId); return cb.equal(metadataIdAttributePath, cb.literal(metadataId)); } }; } private  MetadataValidationSpecs(); static Specification<MetadataValidation> isInvalidAndRequiredForMetadata(final int metadataId); static Specification<MetadataValidation> hasMetadataId(final int metadataId);  }
@Test public void testHasMetadataId() throws Exception { MetadataValidation md1 = _metadataValidationRepo.save(newMetadataValidation()); md1.setValid(true); _metadataValidationRepo.save(md1); final List<MetadataValidation> found = _metadataValidationRepo.findAll(hasMetadataId(md1.getId().getMetadataId())); assertEquals(1, found.size()); assertEquals(md1.getId(), found.get(0).getId()); }