private function addToIdentityMap($object)
    {
        $oid = spl_object_hash($object);
        if (isset($this->objects[$oid])) {
            return;
        }

        $class = $this->manager->getClassMetadata(get_class($object));
        $id = $class->getSingleIdentifier($object);

        if (empty($id)) {
            throw new InvalidIdentifierException('Documents must have an identifier in order to be added to the identity map.');
        }

        $this->objects[$oid] = $object;
        $this->identityMap[$class->name][$id] = $object;
        $this->documentStates[$oid] = self::STATE_MANAGED;
    }