Program: 104844
Project: 104844
Buggy source:
/** 
 * <p> Converts an entity (POJO) to a DBObject (for use with low-level driver); A special field will be added to keep track of the class:   {@link Mapper.CLASS_NAME_FIELDNAME} </p>
 * @param entity The POJO
 * @param involvedObjects A Map of (already converted) POJOs
 */
public DBObject toDBObject(Object entity,Map<Object,DBObject> involvedObjects){
  BasicDBObject dbObject=new BasicDBObject();
  MappedClass mc=getMappedClass(entity);
  if (mc.getEntityAnnotation() == null || !mc.getEntityAnnotation().noClassnameStored())   dbObject.put(CLASS_NAME_FIELDNAME,entity.getClass().getName());
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PrePersist.class,entity,dbObject,this);
  for (  MappedField mf : mc.getPersistenceFields()) {
    try {
      Class<? extends Annotation> annType=null;
      if (mf.hasAnnotation(NotSaved.class))       continue;
      for (      Class<? extends Annotation> testType : new Class[]{Id.class,Property.class,Embedded.class,Serialized.class,Reference.class}) {
        if (mf.hasAnnotation(testType)) {
          annType=testType;
          break;
        }
      }
      if (Id.class.equals(annType)) {
        Object idVal=mf.getFieldValue(entity);
        if (idVal != null) {
          if (!mf.isTypeMongoCompatible() && !converters.hasSimpleValueConverter(mf)) {
            opts.embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
          }
 else {
            Object dbVal=converters.encode(idVal);
            dbObject.put(ID_KEY,dbVal);
          }
        }
      }
 else       if (Property.class.equals(annType) || Serialized.class.equals(annType) || mf.isTypeMongoCompatible()|| (converters.hasSimpleValueConverter(mf)))       opts.valueMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
 else       if (Reference.class.equals(annType))       opts.referenceMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
 else       if (Embedded.class.equals(annType)) {
        opts.embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
      }
 else {
        logger.debug("String_Node_Str" + mf);
        opts.embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
      }
    }
 catch (    Exception e) {
      throw new MappingException("String_Node_Str" + mf.getFullName(),e);
    }
  }
  if (involvedObjects != null)   involvedObjects.put(entity,dbObject);
  mc.callLifecycleMethods(PreSave.class,entity,dbObject,this);
  return dbObject;
}

Fixed version (ground truth):
/** 
 * <p> Converts an entity (POJO) to a DBObject (for use with low-level driver); A special field will be added to keep track of the class:   {@link Mapper.CLASS_NAME_FIELDNAME} </p>
 * @param entity The POJO
 * @param involvedObjects A Map of (already converted) POJOs
 */
public DBObject toDBObject(Object entity,Map<Object,DBObject> involvedObjects){
  BasicDBObject dbObject=new BasicDBObject();
  MappedClass mc=getMappedClass(entity);
  if (mc.getEntityAnnotation() == null || !mc.getEntityAnnotation().noClassnameStored())   dbObject.put(CLASS_NAME_FIELDNAME,entity.getClass().getName());
  dbObject=(BasicDBObject)mc.callLifecycleMethods(PrePersist.class,entity,dbObject,this);
  for (  MappedField mf : mc.getPersistenceFields()) {
    try {
      Class<? extends Annotation> annType=null;
      if (mf.hasAnnotation(NotSaved.class))       continue;
      for (      Class<? extends Annotation> testType : new Class[]{Id.class,Property.class,Embedded.class,Serialized.class,Reference.class}) {
        if (mf.hasAnnotation(testType)) {
          annType=testType;
          break;
        }
      }
      if (Id.class.equals(annType)) {
        Object idVal=mf.getFieldValue(entity);
        if (idVal != null) {
          if (!mf.isTypeMongoCompatible() && !converters.hasSimpleValueConverter(mf)) {
            opts.embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
          }
 else {
            Object dbVal=converters.encode(idVal);
            dbObject.put(ID_KEY,dbVal);
          }
        }
      }
 else       if (Property.class.equals(annType) || Serialized.class.equals(annType) || mf.isTypeMongoCompatible()|| (converters.hasSimpleValueConverter(mf)))       opts.valueMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
 else       if (Reference.class.equals(annType))       opts.referenceMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
 else       if (Embedded.class.equals(annType)) {
        opts.embeddedMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
      }
 else {
        logger.debug("String_Node_Str" + opts.defaultMapper + "String_Node_Str"+ mf);
        opts.defaultMapper.toDBObject(entity,mf,dbObject,involvedObjects,this);
      }
    }
 catch (    Exception e) {
      throw new MappingException("String_Node_Str" + mf.getFullName(),e);
    }
  }
  if (involvedObjects != null)   involvedObjects.put(entity,dbObject);
  mc.callLifecycleMethods(PreSave.class,entity,dbObject,this);
  return dbObject;
}