Program: 104880
Project: 104880
Buggy source:
Object fromDb(DBObject dbObject,final Object entity,Map<Key,Object> retrieved){
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
    Key key=new Key(entity.getClass(),dbObject.get(ID_KEY));
    Object cachedInstance=retrieved.get(key);
    if (cachedInstance != null)     return cachedInstance;
 else     retrieved.put(key,entity);
  }
  MappedClass mc=getMappedClass(entity);
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PreLoad.class,entity,dbObject,this);
  try {
    for (    MappedField mf : mc.getPersistenceFields()) {
      if (mf.hasAnnotation(Id.class)) {
        if (dbObject.get(ID_KEY) != null) {
          mf.setFieldValue(entity,converters.decode(mf.getType(),dbObject.get(ID_KEY)));
        }
      }
 else       if (mf.hasAnnotation(Property.class) || mf.hasAnnotation(Serialized.class) || mf.isTypeMongoCompatible()|| converters.hasSimpleValueConverter(mf))       valueMapper.fromDBObject(dbObject,mf,entity);
 else       if (mf.hasAnnotation(Embedded.class))       embeddedMapper.fromDBObject(dbObject,mf,entity,retrieved);
 else       if (mf.hasAnnotation(Reference.class))       referenceMapper.fromDBObject(dbObject,mf,entity,retrieved);
 else {
        embeddedMapper.fromDBObject(dbObject,mf,entity,retrieved);
      }
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
    String id=dbObject.get(ID_KEY).toString();
    Key key=new Key(entity.getClass(),id);
    retrieved.put(key,entity);
  }
  mc.callLifecycleMethods(PostLoad.class,entity,dbObject,this);
  return entity;
}

Fixed version (ground truth):
Object fromDb(DBObject dbObject,final Object entity,Map<Key,Object> retrieved){
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
    Key key=new Key(entity.getClass(),dbObject.get(ID_KEY));
    Object cachedInstance=retrieved.get(key);
    if (cachedInstance != null)     return cachedInstance;
 else     retrieved.put(key,entity);
  }
  MappedClass mc=getMappedClass(entity);
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PreLoad.class,entity,dbObject,this);
  try {
    for (    MappedField mf : mc.getPersistenceFields()) {
      if (mf.hasAnnotation(Id.class)) {
        setIdValue(entity,mf,dbObject,retrieved);
      }
 else       if (mf.hasAnnotation(Property.class) || mf.hasAnnotation(Serialized.class) || mf.isTypeMongoCompatible()|| converters.hasSimpleValueConverter(mf))       valueMapper.fromDBObject(dbObject,mf,entity);
 else       if (mf.hasAnnotation(Embedded.class))       embeddedMapper.fromDBObject(dbObject,mf,entity,retrieved);
 else       if (mf.hasAnnotation(Reference.class))       referenceMapper.fromDBObject(dbObject,mf,entity,retrieved);
 else {
        embeddedMapper.fromDBObject(dbObject,mf,entity,retrieved);
      }
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  if (dbObject.containsField(ID_KEY) && getMappedClass(entity).getIdField() != null) {
    String id=dbObject.get(ID_KEY).toString();
    Key key=new Key(entity.getClass(),id);
    retrieved.put(key,entity);
  }
  mc.callLifecycleMethods(PostLoad.class,entity,dbObject,this);
  return entity;
}