Program: 176672
Project: 176672
Buggy source:
/** 
 * Writes an entity to database
 */
@Override protected void onPersist(EntityMetadata entityMetadata,Object entity,Object id,List<RelationHolder> rlHolders){
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + entity);
  checkActiveTransaction();
  GraphDatabaseService graphDb=getConnection();
  try {
    Node node=mapper.getNodeFromEntity(entity,graphDb,entityMetadata,isUpdate);
    if (node != null) {
      ((Neo4JTransaction)resource).addProcessedNode(id,node);
      if (!rlHolders.isEmpty()) {
        for (        RelationHolder rh : rlHolders) {
          EntityMetadata targetNodeMetadata=KunderaMetadataManager.getEntityMetadata(rh.getRelationValue().getClass());
          Object targetNodeKey=PropertyAccessorHelper.getId(rh.getRelationValue(),targetNodeMetadata);
          Node targetNode=null;
          if (isEntityForNeo4J(targetNodeMetadata)) {
            targetNode=((Neo4JTransaction)resource).getProcessedNode(targetNodeKey);
          }
 else {
            if (!isUpdate) {
              targetNode=mapper.createProxyNode(id,targetNodeKey,graphDb,entityMetadata,targetNodeMetadata);
            }
          }
          if (targetNode != null) {
            DynamicRelationshipType relType=DynamicRelationshipType.withName(rh.getRelationName());
            Relationship relationship=node.createRelationshipTo(targetNode,relType);
            Object relationshipObj=rh.getRelationVia();
            if (relationshipObj != null) {
              mapper.populateRelationshipProperties(entityMetadata,targetNodeMetadata,relationship,relationshipObj);
              EntityMetadata relationMetadata=KunderaMetadataManager.getEntityMetadata(relationshipObj.getClass());
              if (!isUpdate) {
                indexer.indexRelationship(relationMetadata,graphDb,relationship);
              }
 else {
                indexer.updateRelationshipIndex(relationMetadata,graphDb,relationship);
              }
            }
          }
        }
      }
      if (!isUpdate) {
        indexer.indexNode(entityMetadata,graphDb,node);
      }
 else {
        indexer.updateNodeIndex(entityMetadata,graphDb,node);
      }
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + entity + "String_Node_Str"+ e.getMessage());
    throw new PersistenceException(e);
  }
}

Fixed version (ground truth):
/** 
 * Writes an entity to database
 */
@Override protected void onPersist(EntityMetadata entityMetadata,Object entity,Object id,List<RelationHolder> rlHolders){
  if (log.isDebugEnabled())   log.debug("String_Node_Str" + entity);
  checkActiveTransaction();
  GraphDatabaseService graphDb=getConnection();
  try {
    Node node=mapper.getNodeFromEntity(entity,id,graphDb,entityMetadata,isUpdate);
    if (node != null) {
      ((Neo4JTransaction)resource).addProcessedNode(id,node);
      if (!rlHolders.isEmpty()) {
        for (        RelationHolder rh : rlHolders) {
          EntityMetadata targetNodeMetadata=KunderaMetadataManager.getEntityMetadata(rh.getRelationValue().getClass());
          Object targetNodeKey=PropertyAccessorHelper.getId(rh.getRelationValue(),targetNodeMetadata);
          Node targetNode=null;
          if (isEntityForNeo4J(targetNodeMetadata)) {
            targetNode=((Neo4JTransaction)resource).getProcessedNode(targetNodeKey);
          }
 else {
            if (!isUpdate) {
              targetNode=mapper.createProxyNode(id,targetNodeKey,graphDb,entityMetadata,targetNodeMetadata);
            }
          }
          if (targetNode != null) {
            DynamicRelationshipType relType=DynamicRelationshipType.withName(rh.getRelationName());
            Relationship relationship=node.createRelationshipTo(targetNode,relType);
            Object relationshipObj=rh.getRelationVia();
            if (relationshipObj != null) {
              mapper.populateRelationshipProperties(entityMetadata,targetNodeMetadata,relationship,relationshipObj);
              EntityMetadata relationMetadata=KunderaMetadataManager.getEntityMetadata(relationshipObj.getClass());
              if (!isUpdate) {
                indexer.indexRelationship(relationMetadata,graphDb,relationship);
              }
 else {
                indexer.updateRelationshipIndex(relationMetadata,graphDb,relationship);
              }
            }
          }
        }
      }
      if (!isUpdate) {
        indexer.indexNode(entityMetadata,graphDb,node);
      }
 else {
        indexer.updateNodeIndex(entityMetadata,graphDb,node);
      }
    }
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + entity + "String_Node_Str"+ e.getMessage());
    throw new PersistenceException(e);
  }
}