MetadataRelationSpecs { public static Specification<MetadataRelation> hasMetadataId(final Integer metadataId) { return new Specification<MetadataRelation>() { @Override public Predicate toPredicate(Root<MetadataRelation> root, CriteriaQuery<?> query, CriteriaBuilder cb) { final Path<Integer> metadataIdPath = root.get(MetadataRelation_.id).get(MetadataRelationId_.metadataId); return cb.equal(metadataIdPath, metadataId); } }; } private  MetadataRelationSpecs(); static Specification<MetadataRelation> hasMetadataId(final Integer metadataId); static Specification<MetadataRelation> hasRelatedId(final Integer relatedId);  }
@Test public void testHasMetadataId() throws Exception { Metadata metadata1 = _metadataRepo.save(newMetadata(_inc)); Metadata metadata2 = _metadataRepo.save(newMetadata(_inc)); MetadataRelation relation = new MetadataRelation(); relation.setId(new MetadataRelationId(metadata1.getId(), metadata2.getId())); _repo.save(relation); assertEquals(1, _repo.count(hasMetadataId(metadata1.getId()))); assertEquals(0, _repo.count(hasMetadataId(metadata2.getId()))); }