Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine2 - No Metadata Classes to process

Tags:

doctrine-orm

Something is wrong with documentation or me. I do all what documentation says.

When i put in terminal :

$ php vendor/bin/doctrine orm:schema-tool:create

Output is :

No Metadata Classes to process

I read to many posts, and google and try to many examples but nothing.

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html

like image 512
Jony Avatar asked Jul 04 '13 14:07

Jony


5 Answers

I think you took the config example from Doctrine2: getting started:

$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration([__DIR__."/src"], $isDevMode);

The trick is now that the Setup::createAnnotationMetadataConfiguration method uses a SimpleAnnotationReader by default. You can change this behaviour by changing the fifth parameter to false:

$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration([__DIR__."/src"], $isDevMode, null, null, false);

This will force Doctrine to use the not-simple AnnotationReader which can handle your models now!

like image 177
Dennis B. Avatar answered Nov 11 '22 19:11

Dennis B.


TL;DR: Make sure the type of metadata you created matches the "create metadata configuration" method you used.

I encountered the same problem while working through the Doctrine "Getting Started" guide. After looking through the Doctrine code a bit I figured out what was going wrong. Basically, the code in the tutorial in the "Obtaining the EntityManager" section is:

$config = Setup::createAnnotationMetadataConfiguration([__DIR__ . "/src"], $isDevMode);

A little further in the tutorial, in the "Starting with the Product" section, it shows us how to set up the metadata, with an example for each of the possible options for this. The tutorial says:

Metadata for entities are configured using a XML, YAML or Docblock Annotations. This Getting Started Guide will show the mappings for all Mapping Drivers. References in the text will be made to the XML mapping.

Because of this statement, I decided to use the XML configuration. Unfortunately, the createAnnotationMetadataConfiguration method in the tutorial code did not seem to be using the XML file I had created. (In hindsight, it seems much more obvious that this method is specifically referring to annotation metadata, not XML metadata!)

After I changed it to createXMLMetadataConfiguration instead, it worked as expected. So it looks like one possible source of this problem is that the "create metadata configuration" method you used may not match the type of metadata you created.

like image 40
Don't Panic Avatar answered Nov 11 '22 20:11

Don't Panic


Try clearing the cache:

sudo -u www-data php app/console cache:clear --env=dev
like image 34
don-jeremias Avatar answered Nov 11 '22 19:11

don-jeremias


Uncomment the one of the following lines in bootstrap.php:

// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);

Which depends if you created yaml or xml meta config files...

Hope this helps.

like image 22
Aleksandar Stojilkovic Avatar answered Nov 11 '22 20:11

Aleksandar Stojilkovic


Had the same issue with custom Doctrine installation. My solution was to re-set metadata driver:

$config->setMetadataDriverImpl(
    new Doctrine\ORM\Mapping\Driver\AnnotationDriver(
        new Doctrine\Common\Annotations\CachedReader(
            new Doctrine\Common\Annotations\AnnotationReader(),
            new Doctrine\Common\Cache\ArrayCache()
        ),
        ENTITY_DIR
    )
);

Solution from http://support.skipper18.com/1120/how-use-external-tools-generate-doctrine-getters-and-setters?show=1121#a1121 My scenario was generating entities from existing database

The newDefaultAnnotationDriver adds the namespace and the method comments state the following:

If $useSimpleAnnotationReader is true, the notation @Entity will work, otherwise, the notation @ORM\Entity will be supported.

like image 23
michalzuber Avatar answered Nov 11 '22 19:11

michalzuber