Program: 176515
Project: 176515
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(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() != null) {
      if (targetEntityMetadata.equals(entityMetadata)) {
        tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(),entityMetadata.getIdAttribute().getJavaType()));
      }
 else {
        String pu=targetEntityMetadata.getPersistenceUnit();
        Type targetEntityType=targetEntityMetadata.getType();
        Class idClass=targetEntityMetadata.getIdAttribute().getJavaType();
        String idName=((AbstractAttribute)targetEntityMetadata.getIdAttribute()).getJPAColumnName();
        boolean isCompositeId=idClass.isAnnotationPresent(Embeddable.class);
        TableInfo targetTableInfo=new TableInfo(targetEntityMetadata.getTableName(),targetEntityMetadata.isIndexable(),targetEntityType.name(),idClass,idName,isCompositeId);
        if (!pu.equals(persistenceUnit)) {
          List<TableInfo> targetTableInfos=getSchemaInfo(pu);
          addJoinColumnToInfo(relation.getJoinColumnName(),targetTableInfo,targetTableInfos,entityMetadata);
          puToSchemaMetadata.put(pu,targetTableInfos);
        }
 else {
          addJoinColumnToInfo(relation.getJoinColumnName(),targetTableInfo,tableInfos,entityMetadata);
        }
      }
    }
 else     if (relation.isUnary() && relation.getJoinColumnName() != null) {
      tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(),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,false,Type.COLUMN_FAMILY.name(),String.class,joinColumnName.concat(inverseJoinColumnName),false);
        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(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() != null) {
      if (targetEntityMetadata.equals(entityMetadata)) {
        tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(),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(),targetTableInfo,targetTableInfos,entityMetadata);
          puToSchemaMetadata.put(pu,targetTableInfos);
        }
 else {
          addJoinColumnToInfo(relation.getJoinColumnName(),targetTableInfo,tableInfos,entityMetadata);
        }
      }
    }
 else     if (relation.isUnary() && relation.getJoinColumnName() != null) {
      tableInfo.addColumnInfo(getJoinColumn(tableInfo,relation.getJoinColumnName(),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,joinColumnName.concat(inverseJoinColumnName));
        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);
        }
      }
    }
  }
}