public static function getIdentifierType(ClassMetadata $targetEntity)
    {
        $identifier = self::getIdentifier($targetEntity);
        $type = $targetEntity->getTypeOfField($identifier);

        if ($type instanceof Type) {
            return $type;
        }

        if (\is_string($type)) {
            return Type::getType($type);
        }

        $msg = 'The Doctrine DBAL type is not found for "%s::%s" identifier';

        throw new RuntimeException(sprintf($msg, $targetEntity->getName(), $identifier));
    }