CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<?> criteria = builder.createQuery(relationshipClass);
Root<?> root = criteria.from(relationshipClass);
List<Predicate> predicates = new ArrayList<Predicate>();
predicates.add(builder.equal(root.get(fromProperty.getName()),
lookupIdentity(fromIdentity, em)));
predicates.add(builder.equal(root.get(toProperty.getName()),
lookupIdentity(toIdentity, em)));
predicates.add(builder.equal(root.get(relationshipTypeProp.getName()),
lookupRelationshipType(relationshipType, em)));