Program: 176765
Project: 176765
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);
    ForeignKey relationType=relation.getType();
    if (targetEntityMetadata != null && relationType.equals(ForeignKey.ONE_TO_MANY) && relation.getJoinColumnName() != null) {
      if (targetEntityMetadata.equals(entityMetadata)) {
        tableInfo.addColumnInfo(getJoinColumn(relation.getJoinColumnName()));
      }
 else {
        String pu=targetEntityMetadata.getPersistenceUnit();
        Type targetEntityType=targetEntityMetadata.getType();
        Class idClass=entityMetadata.getIdAttribute().getJavaType();
        TableInfo targetTableInfo=new TableInfo(targetEntityMetadata.getTableName(),targetEntityMetadata.isIndexable(),targetEntityType.name(),idClass);
        if (!pu.equals(persistenceUnit)) {
          List<TableInfo> targetTableInfos=getSchemaInfo(pu);
          addJoinColumnToInfo(relation.getJoinColumnName(),targetTableInfo,targetTableInfos);
          puToSchemaMetadata.put(pu,targetTableInfos);
        }
 else {
          addJoinColumnToInfo(relation.getJoinColumnName(),targetTableInfo,tableInfos);
        }
      }
    }
 else     if (relation.isUnary() && relation.getJoinColumnName() != null) {
      tableInfo.addColumnInfo(getJoinColumn(relation.getJoinColumnName()));
    }
 else     if ((relationType.equals(ForeignKey.MANY_TO_MANY)) && (entityMetadata.isRelationViaJoinTable())) {
      String joinTableName=relation.getJoinTableMetadata().getJoinTableName();
      TableInfo joinTableInfo=new TableInfo(joinTableName,false,Type.COLUMN_FAMILY.name(),null);
      if (!tableInfos.isEmpty() && !tableInfos.contains(joinTableInfo) || tableInfos.isEmpty()) {
        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);
    ForeignKey relationType=relation.getType();
    if (targetEntityMetadata != null && relationType.equals(ForeignKey.ONE_TO_MANY) && relation.getJoinColumnName() != null) {
      if (targetEntityMetadata.equals(entityMetadata)) {
        tableInfo.addColumnInfo(getJoinColumn(relation.getJoinColumnName()));
      }
 else {
        String pu=targetEntityMetadata.getPersistenceUnit();
        Type targetEntityType=targetEntityMetadata.getType();
        Class idClass=entityMetadata.getIdAttribute().getJavaType();
        TableInfo targetTableInfo=new TableInfo(targetEntityMetadata.getTableName(),targetEntityMetadata.isIndexable(),targetEntityType.name(),idClass);
        if (!pu.equals(persistenceUnit)) {
          List<TableInfo> targetTableInfos=getSchemaInfo(pu);
          addJoinColumnToInfo(relation.getJoinColumnName(),targetTableInfo,targetTableInfos);
          puToSchemaMetadata.put(pu,targetTableInfos);
        }
 else {
          addJoinColumnToInfo(relation.getJoinColumnName(),targetTableInfo,tableInfos);
        }
      }
    }
 else     if (relation.isUnary() && relation.getJoinColumnName() != null) {
      tableInfo.addColumnInfo(getJoinColumn(relation.getJoinColumnName()));
    }
 else     if ((relationType.equals(ForeignKey.MANY_TO_MANY)) && (entityMetadata.isRelationViaJoinTable())) {
      JoinTableMetadata joinTableMetadata=relation.getJoinTableMetadata();
      String joinTableName=joinTableMetadata != null ? joinTableMetadata.getJoinTableName() : null;
      if (joinTableName != null) {
        TableInfo joinTableInfo=new TableInfo(joinTableName,false,Type.COLUMN_FAMILY.name(),null);
        if (!tableInfos.isEmpty() && !tableInfos.contains(joinTableInfo) || tableInfos.isEmpty()) {
          tableInfos.add(joinTableInfo);
        }
      }
    }
  }
}