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)));
criteria.where(predicates.toArray(new Predicate[predicates.size()]));
Object relationship = em.createQuery(criteria).getSingleResult();