Program: 176018
Project: 176018
Buggy source:
/** 
 * parse the relations of entites .
 * @param persistenceUnit
 * @param tableInfos
 * @param entityMetadata
 * @param tableInfo
 * @param relations
 */
private void parseRelations(String persistenceUnit,List<TableInfo> tableInfos,EntityMetadata entityMetadata,TableInfo tableInfo,List<Relation> relations){
  for (  Relation relation : relations) {
    Class entityClass=relation.getTargetEntity();
    EntityMetadata targetEntityMetadata=KunderaMetadataManager.getEntityMetadata(kunderaMetadata,entityClass);
    if (targetEntityMetadata == null) {
      log.error("String_Node_Str" + entityClass + "String_Node_Str");
      throw new SchemaGenerationException("String_Node_Str" + entityClass + "String_Node_Str");
    }
    ForeignKey relationType=relation.getType();
    if (targetEntityMetadata != null && relationType.equals(ForeignKey.ONE_TO_MANY) && relation.getJoinColumnName(kunderaMetadata) != null) {
      if (targetEntityMetadata.equals(entityMetadata)) {
        tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(kunderaMetadata),entityMetadata.getIdAttribute().getJavaType()));
      }
 else {
        String pu=targetEntityMetadata.getPersistenceUnit();
        Type targetEntityType=targetEntityMetadata.getType();
        Class idClass=targetEntityMetadata.getIdAttribute().getJavaType();
        String idName=((AbstractAttribute)targetEntityMetadata.getIdAttribute()).getJPAColumnName();
        TableInfo targetTableInfo=new TableInfo(targetEntityMetadata.getTableName(),targetEntityType.name(),idClass,idName);
        if (!pu.equals(persistenceUnit)) {
          List<TableInfo> targetTableInfos=getSchemaInfo(pu);
          addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata),targetTableInfo,targetTableInfos,entityMetadata);
          puToSchemaMetadata.put(pu,targetTableInfos);
        }
 else {
          addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata),targetTableInfo,tableInfos,entityMetadata);
        }
      }
    }
 else     if (relation.isUnary() && relation.getJoinColumnName(kunderaMetadata) != null) {
      if (!relation.isJoinedByPrimaryKey()) {
        tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(kunderaMetadata),targetEntityMetadata.getIdAttribute().getJavaType()));
      }
    }
 else     if ((relationType.equals(ForeignKey.MANY_TO_MANY)) && (entityMetadata.isRelationViaJoinTable())) {
      JoinTableMetadata joinTableMetadata=relation.getJoinTableMetadata();
      String joinTableName=joinTableMetadata != null ? joinTableMetadata.getJoinTableName() : null;
      String joinColumnName=joinTableMetadata != null ? (String)joinTableMetadata.getJoinColumns().toArray()[0] : null;
      String inverseJoinColumnName=joinTableMetadata != null ? (String)joinTableMetadata.getInverseJoinColumns().toArray()[0] : null;
      if (joinTableName != null) {
        TableInfo joinTableInfo=new TableInfo(joinTableName,Type.COLUMN_FAMILY.name(),String.class,"String_Node_Str");
        if (!tableInfos.isEmpty() && !tableInfos.contains(joinTableInfo) || tableInfos.isEmpty()) {
          joinTableInfo.addColumnInfo(getJoinColumn(joinTableInfo,joinColumnName,entityMetadata.getIdAttribute().getJavaType()));
          joinTableInfo.addColumnInfo(getJoinColumn(joinTableInfo,inverseJoinColumnName,entityMetadata.getIdAttribute().getJavaType()));
          tableInfos.add(joinTableInfo);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * parse the relations of entites .
 * @param persistenceUnit
 * @param tableInfos
 * @param entityMetadata
 * @param tableInfo
 * @param relations
 */
private void parseRelations(String persistenceUnit,List<TableInfo> tableInfos,EntityMetadata entityMetadata,TableInfo tableInfo,List<Relation> relations){
  for (  Relation relation : relations) {
    Class entityClass=relation.getTargetEntity();
    EntityMetadata targetEntityMetadata=KunderaMetadataManager.getEntityMetadata(kunderaMetadata,entityClass);
    if (targetEntityMetadata == null) {
      log.error("String_Node_Str" + entityClass + "String_Node_Str");
      throw new SchemaGenerationException("String_Node_Str" + entityClass + "String_Node_Str");
    }
    ForeignKey relationType=relation.getType();
    if (targetEntityMetadata != null && relationType.equals(ForeignKey.ONE_TO_MANY) && relation.getJoinColumnName(kunderaMetadata) != null) {
      if (targetEntityMetadata.equals(entityMetadata)) {
        tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(kunderaMetadata),entityMetadata.getIdAttribute().getJavaType()));
      }
 else {
        String pu=targetEntityMetadata.getPersistenceUnit();
        Type targetEntityType=targetEntityMetadata.getType();
        Class idClass=targetEntityMetadata.getIdAttribute().getJavaType();
        String idName=((AbstractAttribute)targetEntityMetadata.getIdAttribute()).getJPAColumnName();
        TableInfo targetTableInfo=new TableInfo(targetEntityMetadata.getTableName(),targetEntityType.name(),idClass,idName);
        if (!pu.equals(persistenceUnit)) {
          List<TableInfo> targetTableInfos=getSchemaInfo(pu);
          addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata),targetTableInfo,targetTableInfos,entityMetadata);
          puToSchemaMetadata.put(pu,targetTableInfos);
        }
 else {
          addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata),targetTableInfo,tableInfos,entityMetadata);
        }
      }
    }
 else     if (relation.isUnary() && relation.getJoinColumnName(kunderaMetadata) != null) {
      if (!relation.isJoinedByPrimaryKey()) {
        tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(kunderaMetadata),targetEntityMetadata.getIdAttribute().getJavaType()));
      }
    }
 else     if ((relationType.equals(ForeignKey.MANY_TO_MANY)) && (entityMetadata.isRelationViaJoinTable())) {
      JoinTableMetadata joinTableMetadata=relation.getJoinTableMetadata();
      String joinTableName=joinTableMetadata != null ? joinTableMetadata.getJoinTableName() : null;
      String joinColumnName=joinTableMetadata != null ? (String)joinTableMetadata.getJoinColumns().toArray()[0] : null;
      String inverseJoinColumnName=joinTableMetadata != null ? (String)joinTableMetadata.getInverseJoinColumns().toArray()[0] : null;
      if (joinTableName != null) {
        TableInfo joinTableInfo=new TableInfo(joinTableName,Type.COLUMN_FAMILY.name(),String.class,"String_Node_Str");
        if (!tableInfos.isEmpty() && !tableInfos.contains(joinTableInfo) || tableInfos.isEmpty()) {
          joinTableInfo.addColumnInfo(getJoinColumn(joinTableInfo,joinColumnName,entityMetadata.getIdAttribute().getJavaType()));
          joinTableInfo.addColumnInfo(getJoinColumn(joinTableInfo,inverseJoinColumnName,targetEntityMetadata.getIdAttribute().getJavaType()));
          tableInfos.add(joinTableInfo);
        }
      }
    }
  }
}