Program: 176967
Project: 176967
Buggy source:
/** 
 * Flushes Dirty objects in   {@link PersistenceCache} to databases.
 */
public void flush(){
  if (FlushModeType.COMMIT.equals(getFlushMode())) {
  }
 else   if (FlushModeType.AUTO.equals(getFlushMode())) {
    flushManager.buildFlushStack(PersistenceCache.INSTANCE);
    FlushStack fs=PersistenceCache.INSTANCE.getFlushStack();
    log.debug("String_Node_Str" + fs);
    while (!fs.isEmpty()) {
      Node node=fs.pop();
      EntityMetadata metadata=getMetadata(node.getDataClass());
      node.setClient(getClient(metadata));
      node.flush();
      Map<NodeLink,Node> parents=node.getParents();
      Map<NodeLink,Node> children=node.getChildren();
      if (parents != null && !parents.isEmpty()) {
        for (        NodeLink parentNodeLink : parents.keySet()) {
          parentNodeLink.addLinkProperty(LinkProperty.LINK_VALUE,ObjectGraphBuilder.getEntityId(node.getNodeId()));
        }
      }
      if (children != null && !children.isEmpty()) {
        for (        NodeLink childNodeLink : children.keySet()) {
          childNodeLink.addLinkProperty(LinkProperty.LINK_VALUE,ObjectGraphBuilder.getEntityId(node.getNodeId()));
        }
      }
    }
    Map<String,JoinTableData> joinTableDataMap=PersistenceCache.INSTANCE.getJoinTableDataMap();
    for (    JoinTableData jtData : joinTableDataMap.values()) {
      EntityMetadata m=KunderaMetadataManager.getEntityMetadata(jtData.getEntityClass());
      Client client=getClient(m);
      if (OPERATION.INSERT.equals(jtData.getOperation())) {
        client.persistJoinTable(jtData);
      }
 else       if (OPERATION.DELETE.equals(jtData.getOperation())) {
        for (        Object pk : jtData.getJoinTableRecords().keySet()) {
          client.deleteByColumn(jtData.getJoinTableName(),m.getIdColumn().getName(),pk);
        }
      }
    }
    joinTableDataMap.clear();
  }
}

Fixed version (ground truth):
/** 
 * Flushes Dirty objects in   {@link PersistenceCache} to databases.
 */
public void flush(){
  if (FlushModeType.COMMIT.equals(getFlushMode())) {
  }
 else   if (FlushModeType.AUTO.equals(getFlushMode())) {
    flushManager.buildFlushStack(PersistenceCache.INSTANCE);
    FlushStack fs=PersistenceCache.INSTANCE.getFlushStack();
    log.debug("String_Node_Str" + fs);
    while (!fs.isEmpty()) {
      Node node=fs.pop();
      if (node.isInState(ManagedState.class) || node.isInState(RemovedState.class)) {
        EntityMetadata metadata=getMetadata(node.getDataClass());
        node.setClient(getClient(metadata));
        node.flush();
        Map<NodeLink,Node> parents=node.getParents();
        Map<NodeLink,Node> children=node.getChildren();
        if (parents != null && !parents.isEmpty()) {
          for (          NodeLink parentNodeLink : parents.keySet()) {
            parentNodeLink.addLinkProperty(LinkProperty.LINK_VALUE,ObjectGraphBuilder.getEntityId(node.getNodeId()));
          }
        }
        if (children != null && !children.isEmpty()) {
          for (          NodeLink childNodeLink : children.keySet()) {
            childNodeLink.addLinkProperty(LinkProperty.LINK_VALUE,ObjectGraphBuilder.getEntityId(node.getNodeId()));
          }
        }
      }
    }
    Map<String,JoinTableData> joinTableDataMap=PersistenceCache.INSTANCE.getJoinTableDataMap();
    for (    JoinTableData jtData : joinTableDataMap.values()) {
      EntityMetadata m=KunderaMetadataManager.getEntityMetadata(jtData.getEntityClass());
      Client client=getClient(m);
      if (OPERATION.INSERT.equals(jtData.getOperation())) {
        client.persistJoinTable(jtData);
      }
 else       if (OPERATION.DELETE.equals(jtData.getOperation())) {
        for (        Object pk : jtData.getJoinTableRecords().keySet()) {
          client.deleteByColumn(jtData.getJoinTableName(),m.getIdColumn().getName(),pk);
        }
      }
    }
    joinTableDataMap.clear();
  }
}