Program: 176295
Project: 176295
Buggy source:
/** 
 * Executes on list of entities to be persisted.
 * @param collections collection containing list of db objects.
 * @param entity entity in question.
 * @param id entity id.
 * @param metadata entity metadata
 * @param relationHolders relation holders.
 * @param isUpdate if it is an update
 * @return collection of DB objects.
 */
private Map<String,List<DBObject>> onPersist(Map<String,List<DBObject>> collections,Object entity,Object id,EntityMetadata metadata,List<RelationHolder> relationHolders,boolean isUpdate){
  persistenceUnit=metadata.getPersistenceUnit();
  String documentName=metadata.getTableName();
  DBObject document=null;
  document=new BasicDBObject();
  document=handler.getDocumentFromEntity(document,metadata,entity,relationHolders);
  if (isUpdate) {
    BasicDBObject query=new BasicDBObject();
    MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
    if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) {
      MongoDBUtils.populateCompoundKey(query,metadata,metaModel,id);
    }
 else {
      query.put("String_Node_Str",MongoDBUtils.populateValue(id,id.getClass()));
    }
    DBCollection dbCollection=mongoDb.getCollection(documentName);
    DBObject obj=dbCollection.findOne(query);
    obj.putAll(document);
    dbCollection.save(obj);
  }
 else {
    List<DBObject> dbStatements=null;
    if (collections.containsKey(documentName)) {
      dbStatements=collections.get(documentName);
      dbStatements.add(document);
    }
 else {
      dbStatements=new ArrayList<DBObject>();
      dbStatements.add(document);
      collections.put(documentName,dbStatements);
    }
  }
  return collections;
}

Fixed version (ground truth):
/** 
 * Executes on list of entities to be persisted.
 * @param collections collection containing list of db objects.
 * @param entity entity in question.
 * @param id entity id.
 * @param metadata entity metadata
 * @param relationHolders relation holders.
 * @param isUpdate if it is an update
 * @return collection of DB objects.
 */
private Map<String,List<DBObject>> onPersist(Map<String,List<DBObject>> collections,Object entity,Object id,EntityMetadata metadata,List<RelationHolder> relationHolders,boolean isUpdate){
  persistenceUnit=metadata.getPersistenceUnit();
  String documentName=metadata.getTableName();
  DBObject document=null;
  document=new BasicDBObject();
  document=handler.getDocumentFromEntity(document,metadata,entity,relationHolders);
  if (isUpdate) {
    BasicDBObject query=new BasicDBObject();
    MetamodelImpl metaModel=(MetamodelImpl)KunderaMetadata.INSTANCE.getApplicationMetadata().getMetamodel(metadata.getPersistenceUnit());
    if (metaModel.isEmbeddable(metadata.getIdAttribute().getBindableJavaType())) {
      MongoDBUtils.populateCompoundKey(query,metadata,metaModel,id);
    }
 else {
      query.put("String_Node_Str",MongoDBUtils.populateValue(id,id.getClass()));
    }
    DBCollection dbCollection=mongoDb.getCollection(documentName);
    DBObject obj=dbCollection.findOne(query);
    if (obj != null) {
      obj.putAll(document);
      dbCollection.save(obj);
    }
 else {
      dbCollection.save(document);
    }
  }
 else {
    List<DBObject> dbStatements=null;
    if (collections.containsKey(documentName)) {
      dbStatements=collections.get(documentName);
      dbStatements.add(document);
    }
 else {
      dbStatements=new ArrayList<DBObject>();
      dbStatements.add(document);
      collections.put(documentName,dbStatements);
    }
  }
  return collections;
}