EOEntity sourceEntity = EOModelGroup.defaultGroup().entityNamed(sourceEntityName);
if(sourceEntity.isAbstractEntity())
log.warn("If you programatically add relationships to an abstract entity, make sure you also add it to child entities");
EOEntity destinationEntity = EOModelGroup.defaultGroup().entityNamed(destinationEntityName);
EOAttribute sourceAttribute = sourceEntity.attributeNamed(sourceAttributeName);
EOAttribute destinationAttribute = destinationEntity.attributeNamed(destinationAttributeName);
EOJoin join = new EOJoin(sourceAttribute, destinationAttribute);
EORelationship relationship = new EORelationship();
relationship.setName(relationshipName);
sourceEntity.addRelationship(relationship);