Add a namespace to an already configured EntityManager

随声附和 提交于 2019-12-02 07:49:33

问题


I've got an EntityManager instance fully configured and working. The question is how to add an additional namespace to this EM?

$em->getConfiguration()->addEntityNamespace('MyGreatBundle', 'My\GreatBundle\Entity');

This does not work, throws the following:

Doctrine\Common\Persistence\Mapping\MappingException: The class 'My\GreatBundle\Entity\User' was not found in the chain configured namespaces


回答1:


I managed to fix this issue, had to add the driver too:

$namespace = 'My\GreatBundle\Entity';
$configuration = $em->getConfiguration();
$annotationDriver = new AnnotationDriver(
    $this->container->get('annotation_reader'),
    [__DIR__ . '/../Entity']
);

/** @var MappingDriverChain $driver */
$driver = $configuration->getMetadataDriverImpl();
$driver->addDriver($annotationDriver, $namespace);

$configuration->addEntityNamespace('MyGreatBundle', $namespace);


来源:https://stackoverflow.com/questions/25177029/add-a-namespace-to-an-already-configured-entitymanager

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