将命名空间添加到已配置的EntityManager

时间:2014-08-07 07:53:46

标签: symfony doctrine-orm entitymanager

我已经完全配置并运行了一个EntityManager实例。问题是如何为此EM添加额外的命名空间?

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

这不起作用,抛出以下内容:

  

Doctrine \ Common \ Persistence \ Mapping \ MappingException:类'我的\ GreatBundle \ Entity \ User'在链配置的命名空间中找不到

1 个答案:

答案 0 :(得分:1)

我设法解决了这个问题,不得不添加驱动程序:

$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);