MetadataRelationSpecs { public static Specification<MetadataRelation> hasRelatedId(final Integer relatedId) { return new Specification<MetadataRelation>() { @Override public Predicate toPredicate(Root<MetadataRelation> root, CriteriaQuery<?> query, CriteriaBuilder cb) { final Path<Integer> relatedIdPath = root.get(MetadataRelation_.id).get(MetadataRelationId_.relatedId); return cb.equal(relatedIdPath, relatedId); } }; } private  MetadataRelationSpecs(); static Specification<MetadataRelation> hasMetadataId(final Integer metadataId); static Specification<MetadataRelation> hasRelatedId(final Integer relatedId);  }
@Test public void testHasRelatedId() 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(0, _repo.count(hasRelatedId(metadata1.getId()))); assertEquals(1, _repo.count(hasRelatedId(metadata2.getId()))); }