Program: 176851
Project: 176851
Buggy source:
/** 
 * Gets the entity from document.
 * @param entityClass the entity class
 * @param m the m
 * @param document the document
 * @param relations the relations
 * @return the entity from document
 */
Object getEntityFromDocument(Class<?> entityClass,EntityMetadata m,DBObject document,List<String> relations){
  Object entity=null;
  try {
    entity=entityClass.newInstance();
    Object rowKey=document.get("String_Node_Str");
    Class<?> rowKeyValueClass=rowKey.getClass();
    Class<?> idClass=m.getIdAttribute().getJavaType();
    Map<String,Object> relationValue=null;
    rowKey=populateValue(rowKey,idClass);
    rowKey=getTranslatedObject(rowKey,rowKeyValueClass,idClass);
    PropertyAccessorHelper.setId(entity,m,rowKey);
    MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
    EntityType entityType=metaModel.entity(entityClass);
    Set<Attribute> columns=entityType.getAttributes();
    for (    Attribute column : columns) {
      String fieldName=((AbstractAttribute)column).getJPAColumnName();
      Class javaType=((AbstractAttribute)column).getBindableJavaType();
      if (metaModel.isEmbeddable(javaType)) {
        onViaEmbeddable(entityType,column,m,entity,metaModel.embeddable(javaType),document);
      }
 else       if (!column.isAssociation()) {
        setColumnValue(document,entity,column);
      }
 else       if (relations != null) {
        if (relationValue == null) {
          relationValue=new HashMap<String,Object>();
        }
        if (relations.contains(fieldName) && !fieldName.equals(((AbstractAttribute)m.getIdAttribute()).getJPAColumnName())) {
          Object colValue=document.get(fieldName);
          relationValue.put(fieldName,colValue);
        }
      }
    }
    if (relationValue != null && !relationValue.isEmpty()) {
      EnhanceEntity e=new EnhanceEntity(entity,PropertyAccessorHelper.getId(entity,m),relationValue);
      return e;
    }
 else {
      return entity;
    }
  }
 catch (  InstantiationException e) {
    log.error("String_Node_Str" + entityClass + "String_Node_Str"+ e.getMessage());
    return entity;
  }
catch (  IllegalAccessException e) {
    log.error("String_Node_Str" + e.getMessage());
    return entity;
  }
catch (  PropertyAccessException e) {
    log.error("String_Node_Str" + e.getMessage());
    return entity;
  }
}

Fixed version (ground truth):
/** 
 * Gets the entity from document.
 * @param entityClass the entity class
 * @param m the m
 * @param document the document
 * @param relations the relations
 * @return the entity from document
 */
Object getEntityFromDocument(Class<?> entityClass,EntityMetadata m,DBObject document,List<String> relations){
  Object entity=null;
  try {
    entity=entityClass.newInstance();
    Object rowKey=document.get("String_Node_Str");
    Class<?> rowKeyValueClass=rowKey.getClass();
    Class<?> idClass=m.getIdAttribute().getJavaType();
    Map<String,Object> relationValue=null;
    rowKey=populateValue(rowKey,idClass);
    rowKey=getTranslatedObject(rowKey,rowKeyValueClass,idClass);
    PropertyAccessorHelper.setId(entity,m,rowKey);
    MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(m.getPersistenceUnit());
    EntityType entityType=metaModel.entity(entityClass);
    Set<Attribute> columns=entityType.getAttributes();
    for (    Attribute column : columns) {
      String fieldName=((AbstractAttribute)column).getJPAColumnName();
      Class javaType=((AbstractAttribute)column).getBindableJavaType();
      if (metaModel.isEmbeddable(javaType)) {
        onViaEmbeddable(entityType,column,m,entity,metaModel.embeddable(javaType),document);
      }
 else       if (!column.isAssociation()) {
        setColumnValue(document,entity,column);
      }
 else       if (relations != null) {
        if (relationValue == null) {
          relationValue=new HashMap<String,Object>();
        }
        if (relations.contains(fieldName) && !fieldName.equals(((AbstractAttribute)m.getIdAttribute()).getJPAColumnName())) {
          Object colValue=document.get(fieldName);
          if (colValue != null) {
            String colFieldName=m.getFieldName(fieldName);
            Attribute attribute=colFieldName != null ? entityType.getAttribute(colFieldName) : null;
            EntityMetadata relationMetadata=KunderaMetadataManager.getEntityMetadata(attribute.getJavaType());
            colValue=getTranslatedObject(colValue,colValue.getClass(),relationMetadata.getIdAttribute().getJavaType());
          }
          relationValue.put(fieldName,colValue);
        }
      }
    }
    if (relationValue != null && !relationValue.isEmpty()) {
      EnhanceEntity e=new EnhanceEntity(entity,PropertyAccessorHelper.getId(entity,m),relationValue);
      return e;
    }
 else {
      return entity;
    }
  }
 catch (  InstantiationException e) {
    log.error("String_Node_Str" + entityClass + "String_Node_Str"+ e.getMessage());
    return entity;
  }
catch (  IllegalAccessException e) {
    log.error("String_Node_Str" + e.getMessage());
    return entity;
  }
catch (  PropertyAccessException e) {
    log.error("String_Node_Str" + e.getMessage());
    return entity;
  }
}