Program: 176636
Project: 176636
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(),entityMetadata.getIdAttribute().getBindableJavaType()));
      }
 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(relation.getJoinColumnName(),targetEntityMetadata.getIdAttribute().getBindableJavaType()));
    }
 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(joinColumnName,entityMetadata.getIdAttribute().getBindableJavaType()));
          joinTableInfo.addColumnInfo(getJoinColumn(inverseJoinColumnName,targetEntityMetadata.getIdAttribute().getBindableJavaType()));
          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=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(relation.getJoinColumnName()));
    }
 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(joinColumnName));
          joinTableInfo.addColumnInfo(getJoinColumn(inverseJoinColumnName));
          tableInfos.add(joinTableInfo);
        }
      }
    }
  }
}