public function addToIdentityMap(object $document) : bool
    {
        $class = $this->dm->getClassMetadata(get_class($document));
        $id    = $this->getIdForIdentityMap($document);

        if (isset($this->identityMap[$class->name][$id])) {
            return false;
        }

        $this->identityMap[$class->name][$id] = $document;

        if ($document instanceof NotifyPropertyChanged &&
            ( ! $document instanceof GhostObjectInterface || $document->isProxyInitialized())) {
            $document->addPropertyChangedListener($this);
        }

        return true;
    }