title: Symfony- Error ocurred when I try to make an entity
body: <p>When I use: php bin/console make:entity to create a new db entity, I get the following error:</p>
  <p>In DoctrineHelper.php line 180:
  Class &quot;Doctrine\Persistence\Mapping\Driver\AnnotationDriver&quot; does not exist</p>
  <p>This is my composer.json:</p>
  <pre><code>{
      &quot;type&quot;: &quot;project&quot;,
      &quot;license&quot;: &quot;proprietary&quot;,
      &quot;require&quot;: {
          &quot;php&quot;: &quot;&gt;=7.1.3&quot;,
          &quot;ext-ctype&quot;: &quot;*&quot;,
          &quot;ext-iconv&quot;: &quot;*&quot;,
          &quot;doctrine/annotations&quot;: &quot;^1.13&quot;,
          &quot;doctrine/dbal&quot;: &quot;^3.3&quot;,
          &quot;doctrine/doctrine-bundle&quot;: &quot;^2.6&quot;,
          &quot;doctrine/doctrine-migrations-bundle&quot;: &quot;^3.2&quot;,
          &quot;doctrine/orm&quot;: &quot;^2.12&quot;,
          &quot;sensio/framework-extra-bundle&quot;: &quot;^6.2&quot;,
          &quot;symfony/console&quot;: &quot;4.4.*&quot;,
          &quot;symfony/dotenv&quot;: &quot;4.4.*&quot;,
          &quot;symfony/flex&quot;: &quot;^1.3.1&quot;,
          &quot;symfony/form&quot;: &quot;4.4.*&quot;,
          &quot;symfony/framework-bundle&quot;: &quot;4.4.*&quot;,
          &quot;symfony/options-resolver&quot;: &quot;4.4.*&quot;,
          &quot;symfony/property-access&quot;: &quot;4.4.*&quot;,
          &quot;symfony/proxy-manager-bridge&quot;: &quot;4.4.*&quot;,
          &quot;symfony/twig-bundle&quot;: &quot;4.4.*&quot;,
          &quot;symfony/yaml&quot;: &quot;4.4.*&quot;,
          &quot;twig/extra-bundle&quot;: &quot;^2.12|^3.0&quot;,
          &quot;twig/twig&quot;: &quot;^2.12|^3.0&quot;
      },
      &quot;require-dev&quot;: {
          &quot;symfony/maker-bundle&quot;: &quot;*&quot;,
          &quot;symfony/web-server-bundle&quot;: &quot;4.4.*&quot;
      },
      &quot;config&quot;: {
          &quot;allow-plugins&quot;: {
              &quot;composer/package-versions-deprecated&quot;: true,
              &quot;symfony/flex&quot;: true
          },
          &quot;preferred-install&quot;: {
              &quot;*&quot;: &quot;dist&quot;
          },
          &quot;sort-packages&quot;: true
      },
      &quot;autoload&quot;: {
          &quot;psr-4&quot;: {
              &quot;App\\&quot;: &quot;src/&quot;
          }
      },
      &quot;autoload-dev&quot;: {
          &quot;psr-4&quot;: {
              &quot;App\\Tests\\&quot;: &quot;tests/&quot;
          }
      },
      &quot;replace&quot;: {
          &quot;paragonie/random_compat&quot;: &quot;2.*&quot;,
          &quot;symfony/polyfill-ctype&quot;: &quot;*&quot;,
          &quot;symfony/polyfill-iconv&quot;: &quot;*&quot;,
          &quot;symfony/polyfill-php71&quot;: &quot;*&quot;,
          &quot;symfony/polyfill-php70&quot;: &quot;*&quot;,
          &quot;symfony/polyfill-php56&quot;: &quot;*&quot;
      },
      &quot;scripts&quot;: {
          &quot;auto-scripts&quot;: {
              &quot;cache:clear&quot;: &quot;symfony-cmd&quot;,
              &quot;assets:install %PUBLIC_DIR%&quot;: &quot;symfony-cmd&quot;
          },
          &quot;post-install-cmd&quot;: [
              &quot;@auto-scripts&quot;
          ],
          &quot;post-update-cmd&quot;: [
              &quot;@auto-scripts&quot;
          ]
      },
      &quot;conflict&quot;: {
          &quot;symfony/symfony&quot;: &quot;*&quot;
      },
      &quot;extra&quot;: {
          &quot;symfony&quot;: {
              &quot;allow-contrib&quot;: false,
              &quot;require&quot;: &quot;4.4.*&quot;
          }
      }
  }
  </code></pre>
  <p>This is my DoctrineHelper.php:</p>
  <pre><code>&lt;?php
  
  /*
   * This file is part of the Symfony MakerBundle package.
   *
   * (c) Fabien Potencier &lt;fabien@symfony.com&gt;
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
   */
  
  namespace Symfony\Bundle\MakerBundle\Doctrine;
  
  use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
  use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
  use Doctrine\Common\Persistence\Mapping\MappingException as LegacyPersistenceMappingException;
  use Doctrine\DBAL\Connection;
  use Doctrine\ORM\EntityManagerInterface;
  use Doctrine\ORM\Mapping\Driver\AttributeDriver;
  use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
  use Doctrine\ORM\Mapping\NamingStrategy;
  use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
  use Doctrine\Persistence\ManagerRegistry;
  use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
  use Doctrine\Persistence\Mapping\ClassMetadata;
  use Doctrine\Persistence\Mapping\Driver\AnnotationDriver;
  use Doctrine\Persistence\Mapping\Driver\MappingDriver;
  use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
  use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException;
  use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
  use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil;
  
  /**
   * @author Fabien Potencier &lt;fabien@symfony.com&gt;
   * @author Ryan Weaver &lt;ryan@knpuniversity.com&gt;
   * @author Sadicov Vladimir &lt;sadikoff@gmail.com&gt;
   *
   * @internal
   */
  final class DoctrineHelper
  {
      /**
       * @var string
       */
      private $entityNamespace;
      private $phpCompatUtil;
  
      /**
       * @var ManagerRegistry
       */
      private $registry;
  
      /**
       * @var array|null
       */
      private $mappingDriversByPrefix;
  
      private $attributeMappingSupport;
  
      /**
       * @var ManagerRegistry|LegacyManagerRegistry
       */
      public function __construct(string $entityNamespace, PhpCompatUtil $phpCompatUtil, $registry = null, bool $attributeMappingSupport = false, array $annotatedPrefixes = null)
      {
          $this-&gt;entityNamespace = trim($entityNamespace, '\\');
          $this-&gt;phpCompatUtil = $phpCompatUtil;
          $this-&gt;registry = $registry;
          $this-&gt;attributeMappingSupport = $attributeMappingSupport;
          $this-&gt;mappingDriversByPrefix = $annotatedPrefixes;
      }
  
      /**
       * @return LegacyManagerRegistry|ManagerRegistry
       */
      public function getRegistry()
      {
          // this should never happen: we will have checked for the
          // DoctrineBundle dependency before calling this
          if (null === $this-&gt;registry) {
              throw new \Exception('Somehow the doctrine service is missing. Is DoctrineBundle installed?');
          }
  
          return $this-&gt;registry;
      }
  
      private function isDoctrineInstalled(): bool
      {
          return null !== $this-&gt;registry;
      }
  
      public function getEntityNamespace(): string
      {
          return $this-&gt;entityNamespace;
      }
  
      public function doesClassUseDriver(string $className, string $driverClass): bool
      {
          try {
              /** @var EntityManagerInterface $em */
              $em = $this-&gt;getRegistry()-&gt;getManagerForClass($className);
          } catch (\ReflectionException $exception) {
              // this exception will be thrown by the registry if the class isn't created yet.
              // an example case is the &quot;make:entity&quot; command, which needs to know which driver is used for the class to determine
              // if the class should be generated with attributes or annotations. If this exception is thrown, we will check based on the
              // namespaces for the given $className and compare it with the doctrine configuration to get the correct MappingDriver.
  
              return $this-&gt;isInstanceOf($this-&gt;getMappingDriverForNamespace($className), $driverClass);
          }
  
          if (null === $em) {
              throw new \InvalidArgumentException(sprintf('Cannot find the entity manager for class &quot;%s&quot;', $className));
          }
  
          if (null === $this-&gt;mappingDriversByPrefix) {
              // doctrine-bundle &lt;= 2.2
              $metadataDriver = $em-&gt;getConfiguration()-&gt;getMetadataDriverImpl();
  
              if (!$this-&gt;isInstanceOf($metadataDriver, MappingDriverChain::class)) {
                  return $this-&gt;isInstanceOf($metadataDriver, $driverClass);
              }
  
              foreach ($metadataDriver-&gt;getDrivers() as $namespace =&gt; $driver) {
                  if (0 === strpos($className, $namespace)) {
                      return $this-&gt;isInstanceOf($driver, $driverClass);
                  }
              }
  
              return $this-&gt;isInstanceOf($metadataDriver-&gt;getDefaultDriver(), $driverClass);
          }
  
          $managerName = array_search($em, $this-&gt;getRegistry()-&gt;getManagers(), true);
  
          foreach ($this-&gt;mappingDriversByPrefix[$managerName] as [$prefix, $prefixDriver]) {
              if (0 === strpos($className, $prefix)) {
                  return $this-&gt;isInstanceOf($prefixDriver, $driverClass);
              }
          }
  
          return false;
      }
  
      public function isClassAnnotated(string $className): bool
      {
          return $this-&gt;doesClassUseDriver($className, AnnotationDriver::class);
      }
  
      public function doesClassUsesAttributes(string $className): bool
      {
          return $this-&gt;doesClassUseDriver($className, AttributeDriver::class);
      }
  
      public function isDoctrineSupportingAttributes(): bool
      {
          return $this-&gt;isDoctrineInstalled() &amp;&amp; $this-&gt;attributeMappingSupport &amp;&amp; $this-&gt;phpCompatUtil-&gt;canUseAttributes();
      }
  
      public function getEntitiesForAutocomplete(): array
      {
          $entities = [];
  
          if ($this-&gt;isDoctrineInstalled()) {
              $allMetadata = $this-&gt;getMetadata();
  
              foreach (array_keys($allMetadata) as $classname) {
                  $entityClassDetails = new ClassNameDetails($classname, $this-&gt;entityNamespace);
                  $entities[] = $entityClassDetails-&gt;getRelativeName();
              }
          }
  
          sort($entities);
  
          return $entities;
      }
  
      /**
       * @return array|ClassMetadata|LegacyClassMetadata
       */
      public function getMetadata(string $classOrNamespace = null, bool $disconnected = false)
      {
          $classNames = (new \ReflectionClass(AnnotationDriver::class))-&gt;getProperty('classNames');
          $classNames-&gt;setAccessible(true);
  
          // Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
          foreach ($this-&gt;mappingDriversByPrefix ?? [] as $managerName =&gt; $prefixes) {
              foreach ($prefixes as [$prefix, $annotationDriver]) {
                  if (null !== $annotationDriver) {
                      $classNames-&gt;setValue($annotationDriver, null);
                  }
              }
          }
  
          $metadata = [];
  
          /** @var EntityManagerInterface $em */
          foreach ($this-&gt;getRegistry()-&gt;getManagers() as $em) {
              $cmf = $em-&gt;getMetadataFactory();
  
              if ($disconnected) {
                  try {
                      $loaded = $cmf-&gt;getAllMetadata();
                  } catch (ORMMappingException $e) {
                      $loaded = $this-&gt;isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf-&gt;getLoadedMetadata() : [];
                  } catch (LegacyPersistenceMappingException $e) {
                      $loaded = $this-&gt;isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf-&gt;getLoadedMetadata() : [];
                  } catch (PersistenceMappingException $e) {
                      $loaded = $this-&gt;isInstanceOf($cmf, AbstractClassMetadataFactory::class) ? $cmf-&gt;getLoadedMetadata() : [];
                  }
  
                  $cmf = new DisconnectedClassMetadataFactory();
                  $cmf-&gt;setEntityManager($em);
  
                  foreach ($loaded as $m) {
                      $cmf-&gt;setMetadataFor($m-&gt;getName(), $m);
                  }
  
                  if (null === $this-&gt;mappingDriversByPrefix) {
                      // Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
                      $metadataDriver = $em-&gt;getConfiguration()-&gt;getMetadataDriverImpl();
                      if ($this-&gt;isInstanceOf($metadataDriver, MappingDriverChain::class)) {
                          foreach ($metadataDriver-&gt;getDrivers() as $driver) {
                              if ($this-&gt;isInstanceOf($driver, AnnotationDriver::class)) {
                                  $classNames-&gt;setValue($driver, null);
                              }
                          }
                      }
                  }
              }
  
              foreach ($cmf-&gt;getAllMetadata() as $m) {
                  if (null === $classOrNamespace) {
                      $metadata[$m-&gt;getName()] = $m;
                  } else {
                      if ($m-&gt;getName() === $classOrNamespace) {
                          return $m;
                      }
  
                      if (0 === strpos($m-&gt;getName(), $classOrNamespace)) {
                          $metadata[$m-&gt;getName()] = $m;
                      }
                  }
              }
          }
  
          return $metadata;
      }
  
      public function createDoctrineDetails(string $entityClassName): ?EntityDetails
      {
          $metadata = $this-&gt;getMetadata($entityClassName);
  
          if ($this-&gt;isInstanceOf($metadata, ClassMetadata::class)) {
              return new EntityDetails($metadata);
          }
  
          return null;
      }
  
      public function isClassAMappedEntity(string $className): bool
      {
          if (!$this-&gt;isDoctrineInstalled()) {
              return false;
          }
  
          return (bool) $this-&gt;getMetadata($className);
      }
  
      private function isInstanceOf($object, string $class): bool
      {
          if (!\is_object($object)) {
              return false;
          }
  
          $legacyClass = str_replace('Doctrine\\Persistence\\', 'Doctrine\\Common\\Persistence\\', $class);
  
          return $object instanceof $class || $object instanceof $legacyClass;
      }
  
      public function getPotentialTableName(string $className): string
      {
          $entityManager = $this-&gt;getRegistry()-&gt;getManager();
  
          if (!$entityManager instanceof EntityManagerInterface) {
              throw new \RuntimeException('ObjectManager is not an EntityManagerInterface.');
          }
  
          /** @var NamingStrategy $namingStrategy */
          $namingStrategy = $entityManager-&gt;getConfiguration()-&gt;getNamingStrategy();
  
          return $namingStrategy-&gt;classToTableName($className);
      }
  
      public function isKeyword(string $name): bool
      {
          /** @var Connection $connection */
          $connection = $this-&gt;getRegistry()-&gt;getConnection();
  
          return $connection-&gt;getDatabasePlatform()-&gt;getReservedKeywordsList()-&gt;isKeyword($name);
      }
  
      /**
       * this method tries to find the correct MappingDriver for the given namespace/class
       * To determine which MappingDriver belongs to the class we check the prefixes configured in Doctrine and use the
       * prefix that has the closest match to the given $namespace.
       *
       * this helper function is needed to create entities with the configuration of doctrine if they are not yet been registered
       * in the ManagerRegistry
       */
      private function getMappingDriverForNamespace(string $namespace): ?MappingDriver
      {
          $lowestCharacterDiff = null;
          $foundDriver = null;
  
          foreach ($this-&gt;mappingDriversByPrefix ?? [] as $mappings) {
              foreach ($mappings as [$prefix, $driver]) {
                  $diff = substr_compare($namespace, $prefix, 0);
  
                  if ($diff &gt;= 0 &amp;&amp; (null === $lowestCharacterDiff || $diff &lt; $lowestCharacterDiff)) {
                      $lowestCharacterDiff = $diff;
                      $foundDriver = $driver;
                  }
              }
          }
  
          return $foundDriver;
      }
  }
  </code></pre>
  <p>Line 180 is:</p>
  <pre><code>$classNames = (new \ReflectionClass(AnnotationDriver::class))-&gt;getProperty('classNames');
  </code></pre>
  <p>What could be the problem? I tried a lot of things but I'am not capable of solve it</p>