No mapped Doctrine ORM entities according to the current configuration

前端 未结 4 1774
闹比i
闹比i 2021-02-04 19:31

I\'ve got a dubious issue. I have a set of existing annotated Doctrine entities which have been successfully used in a Symfony2/Doctrine2 project. However, I\'m currently isolat

相关标签:
4条回答
  • 2021-02-04 19:48

    The accepted answer is ok but the same thing could be achieved in less verbose manner:

    use Doctrine\ORM\Tools\Setup;
    use Doctrine\ORM\EntityManager;
    
    $paths = array( realpath(__DIR__."/../src/My/Entity") );
    $isDevMode = TRUE;
    
    // the connection configuration
    $dbParams = array(
        'driver'   => 'pdo_mysql',
        'user'     => 'myuser',
        'password' => 's3cr3t',
        'dbname'   => 'mydb',
    );
    
    $config = Setup::createAnnotationMetadataConfiguration(
        $paths, $isDevMode, null, null, false
    );
    $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
    $entityManager = EntityManager::create($dbParams, $config);
    
    //-- This I had to add to support the Mysql enum type.
    $platform = $entityManager->getConnection()->getDatabasePlatform();
    $platform->registerDoctrineTypeMapping('enum', 'string');
    

    All here is about usage of simple annotation driver or not (last parameter of the Setup::createAnnotationMetadataConfiguration function. By default, a simple annotation driver is used which doesn't recognise the @ORM\Entity annotation.

    0 讨论(0)
  • 2021-02-04 19:50

    It turns out that the standard Doctrine config set up [1] doesn't work with my code base, or any code base I have tested with, maybe the docs are outdated. After ploughing through the Interwebs for hours, this is the configuration that finally made it work for me:

    use Doctrine\ORM\Tools\Setup;
    use Doctrine\ORM\EntityManager;
    use Doctrine\Common\Annotations\AnnotationReader;
    
    $paths = array( realpath(__DIR__."/../src/My/Entity") );
    $isDevMode = TRUE;
    
    // the connection configuration
    $dbParams = array(
        'driver'   => 'pdo_mysql',
        'user'     => 'myuser',
        'password' => 's3cr3t',
        'dbname'   => 'mydb',
    );
    
    $cache = new \Doctrine\Common\Cache\ArrayCache();
    
    $reader = new AnnotationReader();
    $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, $paths);
    
    $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
    $config->setMetadataCacheImpl( $cache );
    $config->setQueryCacheImpl( $cache );
    $config->setMetadataDriverImpl( $driver );
    
    $entityManager = EntityManager::create($dbParams, $config);
    
    //-- This I had to add to support the Mysql enum type.
    $platform = $entityManager->getConnection()->getDatabasePlatform();
    $platform->registerDoctrineTypeMapping('enum', 'string');
    

    [1] http://docs.doctrine-project.org/en/latest/tutorials/getting-started.html

    0 讨论(0)
  • 2021-02-04 19:53

    For me it happened that I imported the vendor directory from a different system and it wasn't working properly.

    A simple composer install or php composer.phar install fixed it.

    0 讨论(0)
  • 2021-02-04 19:59

    I have PHP entity in Ressources/config/doctrine/Foo.orm.php but I use annotation.

    Too different way for orm = [Exception]

    You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.

    Just delete the bad entity file

    0 讨论(0)
提交回复
热议问题