private function doPersist($object, array &$visited): void
    {
        $oid = spl_object_hash($object);
        if (isset($visited[$oid])) {
            return;
        }

        $visited[$oid] = true;
        $class = $this->manager->getClassMetadata(get_class($object));

        $documentState = $this->getDocumentState($object, self::STATE_NEW);
        switch ($documentState) {
            case self::STATE_MANAGED:
                break;

            case self::STATE_NEW:
                $this->persistNew($class, $object);
                break;

            case self::STATE_REMOVED:
                unset($this->documentDeletions[$oid]);
                $this->documentStates[$oid] = self::STATE_MANAGED;

                break;
        }

        $this->cascadePersist($object, $visited);
    }