Program: 176981
Project: 176981
Buggy source:
/** 
 * Gets the sql query from jpa.
 * @param entityMetadata the entity metadata
 * @param relations the relations
 * @param primaryKeys the primary keys
 * @return the sql query from jpa
 */
public String getSqlQueryFromJPA(EntityMetadata entityMetadata,List<String> relations,Set<String> primaryKeys){
  String aliasName="String_Node_Str" + entityMetadata.getTableName();
  StringBuilder queryBuilder=new StringBuilder("String_Node_Str");
  queryBuilder.append(aliasName);
  queryBuilder.append("String_Node_Str");
  queryBuilder.append(entityMetadata.getIdColumn().getName());
  for (  String column : entityMetadata.getColumnFieldNames()) {
    queryBuilder.append("String_Node_Str");
    queryBuilder.append(aliasName);
    queryBuilder.append("String_Node_Str");
    queryBuilder.append(column);
  }
  List<EmbeddedColumn> embeddedColumns=entityMetadata.getEmbeddedColumnsAsList();
  for (  EmbeddedColumn embeddedCol : embeddedColumns) {
    for (    Column column : embeddedCol.getColumns()) {
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(aliasName);
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(column.getName());
    }
  }
  for (  String relation : relations) {
    if (!entityMetadata.getIdColumn().getName().equalsIgnoreCase(relation)) {
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(aliasName);
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(relation);
    }
  }
  queryBuilder.append("String_Node_Str");
  queryBuilder.append(entityMetadata.getTableName());
  queryBuilder.append("String_Node_Str");
  queryBuilder.append(aliasName);
  if (filter != null) {
    queryBuilder.append("String_Node_Str");
  }
  if (primaryKeys == null) {
    for (    Object o : conditions) {
      if (o instanceof FilterClause) {
        FilterClause clause=((FilterClause)o);
        String fieldName=getColumnName(clause.getProperty());
        boolean isString=isStringProperty(entityMetadata,fieldName);
        queryBuilder.append(StringUtils.replace(clause.getProperty(),clause.getProperty().substring(0,clause.getProperty().indexOf("String_Node_Str")),aliasName));
        queryBuilder.append("String_Node_Str");
        queryBuilder.append(clause.getCondition());
        if (clause.getCondition().equalsIgnoreCase("String_Node_Str")) {
          queryBuilder.append("String_Node_Str");
        }
        queryBuilder.append("String_Node_Str");
        appendStringPrefix(queryBuilder,isString);
        queryBuilder.append(clause.getValue());
        appendStringPrefix(queryBuilder,isString);
      }
 else {
        queryBuilder.append("String_Node_Str");
        queryBuilder.append(o);
        queryBuilder.append("String_Node_Str");
      }
    }
  }
 else {
    queryBuilder.append(aliasName);
    queryBuilder.append("String_Node_Str");
    queryBuilder.append(entityMetadata.getIdColumn().getName());
    queryBuilder.append("String_Node_Str");
    queryBuilder.append("String_Node_Str");
    int count=0;
    Column col=entityMetadata.getIdColumn();
    boolean isString=col.getField().getType().isAssignableFrom(String.class);
    for (    String key : primaryKeys) {
      appendStringPrefix(queryBuilder,isString);
      queryBuilder.append(key);
      appendStringPrefix(queryBuilder,isString);
      if (++count != primaryKeys.size()) {
        queryBuilder.append("String_Node_Str");
      }
 else {
        queryBuilder.append("String_Node_Str");
      }
    }
  }
  return queryBuilder.toString();
}

Fixed version (ground truth):
/** 
 * Gets the sql query from jpa.
 * @param entityMetadata the entity metadata
 * @param relations the relations
 * @param primaryKeys the primary keys
 * @return the sql query from jpa
 */
public String getSqlQueryFromJPA(EntityMetadata entityMetadata,List<String> relations,Set<String> primaryKeys){
  String aliasName="String_Node_Str" + entityMetadata.getTableName();
  StringBuilder queryBuilder=new StringBuilder("String_Node_Str");
  queryBuilder.append(aliasName);
  queryBuilder.append("String_Node_Str");
  queryBuilder.append(entityMetadata.getIdColumn().getName());
  for (  String column : entityMetadata.getColumnFieldNames()) {
    queryBuilder.append("String_Node_Str");
    queryBuilder.append(aliasName);
    queryBuilder.append("String_Node_Str");
    queryBuilder.append(column);
  }
  List<EmbeddedColumn> embeddedColumns=entityMetadata.getEmbeddedColumnsAsList();
  for (  EmbeddedColumn embeddedCol : embeddedColumns) {
    for (    Column column : embeddedCol.getColumns()) {
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(aliasName);
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(column.getName());
    }
  }
  for (  String relation : relations) {
    if (!entityMetadata.getIdColumn().getName().equalsIgnoreCase(relation)) {
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(aliasName);
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(relation);
    }
  }
  for (  Relation r : entityMetadata.getRelations()) {
    if (r.getJoinColumnName() != null) {
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(aliasName);
      queryBuilder.append("String_Node_Str");
      queryBuilder.append(r.getJoinColumnName());
    }
  }
  queryBuilder.append("String_Node_Str");
  queryBuilder.append(entityMetadata.getTableName());
  queryBuilder.append("String_Node_Str");
  queryBuilder.append(aliasName);
  if (filter != null) {
    queryBuilder.append("String_Node_Str");
  }
  if (primaryKeys == null) {
    for (    Object o : conditions) {
      if (o instanceof FilterClause) {
        FilterClause clause=((FilterClause)o);
        String fieldName=getColumnName(clause.getProperty());
        boolean isString=isStringProperty(entityMetadata,fieldName);
        queryBuilder.append(StringUtils.replace(clause.getProperty(),clause.getProperty().substring(0,clause.getProperty().indexOf("String_Node_Str")),aliasName));
        queryBuilder.append("String_Node_Str");
        queryBuilder.append(clause.getCondition());
        if (clause.getCondition().equalsIgnoreCase("String_Node_Str")) {
          queryBuilder.append("String_Node_Str");
        }
        queryBuilder.append("String_Node_Str");
        appendStringPrefix(queryBuilder,isString);
        queryBuilder.append(clause.getValue());
        appendStringPrefix(queryBuilder,isString);
      }
 else {
        queryBuilder.append("String_Node_Str");
        queryBuilder.append(o);
        queryBuilder.append("String_Node_Str");
      }
    }
  }
 else {
    queryBuilder.append(aliasName);
    queryBuilder.append("String_Node_Str");
    queryBuilder.append(entityMetadata.getIdColumn().getName());
    queryBuilder.append("String_Node_Str");
    queryBuilder.append("String_Node_Str");
    int count=0;
    Column col=entityMetadata.getIdColumn();
    boolean isString=col.getField().getType().isAssignableFrom(String.class);
    for (    String key : primaryKeys) {
      appendStringPrefix(queryBuilder,isString);
      queryBuilder.append(key);
      appendStringPrefix(queryBuilder,isString);
      if (++count != primaryKeys.size()) {
        queryBuilder.append("String_Node_Str");
      }
 else {
        queryBuilder.append("String_Node_Str");
      }
    }
  }
  return queryBuilder.toString();
}