Symfony2/Doctrine2 Invalid Mapping File Exception when trying to generate entities

感情迁移 提交于 2019-12-05 06:39:01

Has described in the doc:

class-names specified in the YAML files should be fully qualified.

So try change the product yaml definition as follow:

SandboxBundle\Entity\Product:
  type: entity
  table: product
    indexes:
  .....

Do the same in the other mapping files.

Hope this help

Try to rename the file

SandboxBundle.Entity.Product.orm.yml

to

Product.orm.yml

and make sure to fully qualify your name in the yaml

SandboxBundle\Entity\Product:
type: entity
table: product
indexes:
.....

you might get an error because of double namespace. Symfony adds the dotted part of the file to the namespace.

[Doctrine\Common\Persistence\Mapping\MappingException]
Invalid mapping file 'SandboxBundle.Entity.SandboxBundle.Entity.Product.orm.yml' for class
'SandboxBundle\Entity\SandboxBundle\Entity\Product'.

Good luck :)

Recently I was experiencing similar "MappingException: Invalid mapping file" exceptions using the following code:

//bootstrap.php
$config = Setup::createYAMLMetadataConfiguration(array(__DIR__ . 
"/../config/dcm"), $isDevMode);

Using Symfony Yaml 2.*, everything worked fine. But with Symfony Yaml ^3.3 I would get the invalid mapping file exception. I traced it to how the different Yaml library parse functions work. When using Doctrine to parse yaml files, it will use the YamlDriver class which loads yaml files using this function:

// vendor/doctrine/orm/lib/Doctrine/Orm/Mapping/Driver/YamlDriver.php
protected function loadMappingFile($file)
{
    return Yaml::parse($file);
}

In Yaml 2.*, passing a filename string to parse works without problem, but with Yaml ^3.3, the parse function expects a yaml string. Some ways to get around this include using xml config files or writing your own Yaml driver and obtaining the config by bypassing the Setup::createYAMLMetadataConfiguration and using the this code:

$config = self::createConfiguration($isDevMode, $proxyDir, $cache);
$config->setMetadataDriverImpl(new \MyNamespace\YamlDriver($paths));

return $config;

Use

php app/console doctrine:generate:entity

to generate an entity automatically by doctrine. You have used

app/console doctrine:generate:entities entityName

I mean

app/console generate:doctrine:entities entityName

(notice the plural "entities" word)Your command is to generate the updated property of an existing entity and to generate his getter and setter methods but not to generate an entity.

My suggestion is:

  1. Delete the existing entity
  2. Generate them again using proper command.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!