protected function loadFromObjectManager(ClassMetadata $metadata, $data)
    {
        // Locate possible ObjectManager
        if (null === $objectManager = $this->getObjectManager($metadata)) {
            return null;
        }

        // Locate possible ClassMetadata
        $classMetadataFactory = $objectManager->getMetadataFactory();

        if ($classMetadataFactory->isTransient($metadata->getName())) {
            // No ClassMetadata found, proceed with normal deserialization
            return null;
        }

        if (! \is_array($data)) {
            // Single identifier, load
            return $objectManager->find($metadata->getName(), $data);
        }

        // Fallback to default constructor if missing identifier(s)
        $classMetadata = $objectManager->getClassMetadata($metadata->getName());
        $identifierList = [];

        foreach ($classMetadata->getIdentifierFieldNames() as $name) {
            if (! \array_key_exists($name, $data)) {
                continue;
            }

            $identifierList[$name] = $data[$name];
        }

        if (0 === \count($identifierList)) {
            return null;
        }

        // Entity update, load it from database
        return $objectManager->find($metadata->getName(), $identifierList);
    }