private function getChildNodename($parentId, $nodename, $child, $parent)
    {
        $childClass = $this->dm->getClassMetadata(get_class($child));
        if ($childClass->nodename && $childClass->reflFields[$childClass->nodename]->getValue($child)) {
            $nodename = $childClass->reflFields[$childClass->nodename]->getValue($child);

            if ($exception = $childClass->isValidNodename($nodename)) {
                throw IdException::illegalName($child, $childClass->nodename, $nodename);
            }
        } else {
            $childId = '';
            if ($childClass->identifier) {
                $childId = $childClass->getIdentifierValue($child);
            }
            if (!$childId) {
                $generator = $this->getIdGenerator($childClass->idGenerator);
                $childId = $generator->generate($child, $childClass, $this->dm, $parent);
            }

            if ('' !== $childId) {
                if ($childId !== $parentId.'/'.PathHelper::getNodeName($childId)) {
                    throw PHPCRException::cannotMoveByAssignment(self::objToStr($child, $this->dm));
                }
                $nodename = PathHelper::getNodeName($childId);
            }
        }

        return $nodename;
    }