【问题标题】:Add a namespace to an already configured EntityManager将命名空间添加到已配置的 EntityManager
【发布时间】:2014-08-07 07:53:46
【问题描述】:

我已经完成了一个 EntityManager 实例的完整配置并且可以正常工作。问题是如何给这个 EM 添加额外的命名空间?

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

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

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

【问题讨论】:

    标签: symfony doctrine-orm entitymanager


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2017-09-21
      • 1970-01-01
      相关资源
      最近更新 更多