core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocumentHelper.java
@SuppressWarnings("unchecked")
  public static boolean hasSameContentOf(final ODocument iCurrent, final ODatabaseDocumentInternal iMyDb, final ODocument iOther,
      final ODatabaseDocumentInternal iOtherDb, RIDMapper ridMapper, final boolean iCheckAlsoIdentity) {
    if (iOther == null)
      return false;

    if (iCheckAlsoIdentity && iCurrent.getIdentity().isValid() && !iCurrent.getIdentity().equals(iOther.getIdentity()))
      return false;

    if (iMyDb != null)
      makeDbCall(iMyDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          if (iCurrent.getInternalStatus() == STATUS.NOT_LOADED)
            iCurrent.reload();
          return null;
        }
      });

    if (iOtherDb != null)
      makeDbCall(iOtherDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          if (iOther.getInternalStatus() == STATUS.NOT_LOADED)
            iOther.reload();
          return null;
        }
      });

    if (iMyDb != null)
      makeDbCall(iMyDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          iCurrent.checkForFields();
          return null;
        }
      });
    else
      iCurrent.checkForFields();

    if (iOtherDb != null)
      makeDbCall(iOtherDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          iOther.checkForFields();
          return null;
        }
      });
    else
      iOther.checkForFields();

    if (iCurrent.fields() != iOther.fields())
      return false;

    // CHECK FIELD-BY-FIELD
    Object myFieldValue;
    Object otherFieldValue;
    for (Entry<String, Object> f : iCurrent) {
      myFieldValue = f.getValue();
      otherFieldValue = iOther._fields.get(f.getKey()).value;

      if (myFieldValue == otherFieldValue)
        continue;

      // CHECK FOR NULLS
      if (myFieldValue == null) {
        if (otherFieldValue != null)
          return false;
      } else if (otherFieldValue == null)
        return false;

      if (myFieldValue != null)
        if (myFieldValue instanceof Set && otherFieldValue instanceof Set) {
          if (!compareSets(iMyDb, (Set<?>) myFieldValue, iOtherDb, (Set<?>) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof Collection && otherFieldValue instanceof Collection) {
          if (!compareCollections(iMyDb, (Collection<?>) myFieldValue, iOtherDb, (Collection<?>) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof ORidBag && otherFieldValue instanceof ORidBag) {
          if (!compareBags(iMyDb, (ORidBag) myFieldValue, iOtherDb, (ORidBag) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof Map && otherFieldValue instanceof Map) {
          if (!compareMaps(iMyDb, (Map<Object, Object>) myFieldValue, iOtherDb, (Map<Object, Object>) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof ODocument && otherFieldValue instanceof ODocument) {
          if (!hasSameContentOf((ODocument) myFieldValue, iMyDb, (ODocument) otherFieldValue, iOtherDb, ridMapper))
            return false;
        } else {
          if (!compareScalarValues(myFieldValue, iMyDb, otherFieldValue, iOtherDb, ridMapper))
            return false;
        }
    }

    return true;
  }
@SuppressWarnings("unchecked")
  public static boolean hasSameContentOf(final ODocument iCurrent, final ODatabaseDocumentInternal iMyDb, final ODocument iOther,
      final ODatabaseDocumentInternal iOtherDb, RIDMapper ridMapper, final boolean iCheckAlsoIdentity) {
    if (iOther == null)
      return false;

    if (iCheckAlsoIdentity && iCurrent.getIdentity().isValid() && !iCurrent.getIdentity().equals(iOther.getIdentity()))
      return false;

    if (iMyDb != null)
      makeDbCall(iMyDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          if (iCurrent.getInternalStatus() == STATUS.NOT_LOADED)
            iCurrent.reload();
          return null;
        }
      });

    if (iOtherDb != null)
      makeDbCall(iOtherDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          if (iOther.getInternalStatus() == STATUS.NOT_LOADED)
            iOther.reload();
          return null;
        }
      });

    if (iMyDb != null)
      makeDbCall(iMyDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          iCurrent.checkForFields();
          return null;
        }
      });
    else
      iCurrent.checkForFields();

    if (iOtherDb != null)
      makeDbCall(iOtherDb, new ODbRelatedCall<Object>() {
        public Object call(ODatabaseDocumentInternal database) {
          iOther.checkForFields();
          return null;
        }
      });
    else
      iOther.checkForFields();

    if (iCurrent.fields() != iOther.fields())
      return false;

    // CHECK FIELD-BY-FIELD
    Object myFieldValue;
    Object otherFieldValue;
    for (Entry<String, Object> f : iCurrent) {
      myFieldValue = f.getValue();
      otherFieldValue = iOther._fields.get(f.getKey()).value;

      if (myFieldValue == otherFieldValue)
        continue;

      // CHECK FOR NULLS
      if (myFieldValue == null) {
        if (otherFieldValue != null)
          return false;
      } else if (otherFieldValue == null)
        return false;

      if (myFieldValue != null)
        if (myFieldValue instanceof Set && otherFieldValue instanceof Set) {
          if (!compareSets(iMyDb, (Set<?>) myFieldValue, iOtherDb, (Set<?>) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof Collection && otherFieldValue instanceof Collection) {
          if (!compareCollections(iMyDb, (Collection<?>) myFieldValue, iOtherDb, (Collection<?>) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof ORidBag && otherFieldValue instanceof ORidBag) {
          if (!compareBags(iMyDb, (ORidBag) myFieldValue, iOtherDb, (ORidBag) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof Map && otherFieldValue instanceof Map) {
          if (!compareMaps(iMyDb, (Map<Object, Object>) myFieldValue, iOtherDb, (Map<Object, Object>) otherFieldValue, ridMapper))
            return false;
        } else if (myFieldValue instanceof ODocument && otherFieldValue instanceof ODocument) {
          if (!hasSameContentOf((ODocument) myFieldValue, iMyDb, (ODocument) otherFieldValue, iOtherDb, ridMapper))
            return false;
        } else {
          if (!compareScalarValues(myFieldValue, iMyDb, otherFieldValue, iOtherDb, ridMapper))
            return false;
        }
    }

    return true;
  }
Makes a deep comparison field by field to check if the passed ODocument instance is identical in the content to the current
one. Instead equals() just checks if the RID are the same.

@param iOther ODocument instance

@return true if the two document are identical, otherwise false

@see #equals(Object)