Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No mapped Doctrine ORM entities according to the current configuration

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 isolating some core functionality of this project into it's own web framework independent library and I can't seem to get the entities to function properly.

At the moment my major concern is the fact that the Doctrine CLI utility is giving me mixed results.

When I do the following:

bin/doctrine orm:validate-schema

I get the following output:

[Mapping]  OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.

But when I do:

bin/doctrine orm:info

I get this:

[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.

I have gone over my configuration a gazillion times now. I've even removed all my entities and left a most basic User entity in there giving me the same scenario.

What could possible be the source of these mixed results?

like image 491
Luke Avatar asked Jan 11 '14 04:01

Luke


1 Answers

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

like image 57
Luke Avatar answered Oct 13 '22 01:10

Luke