将一个命名空间添加到已配置的EntityManager中 [英] Add a namespace to an already configured EntityManager

查看:118
本文介绍了将一个命名空间添加到已配置的EntityManager中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EntityManager实例完全配置和工作。问题是如何向这个EM添加一个额外的命名空间?

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

这不工作,抛出如下:


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



解决方案

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

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


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

解决方案

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

这篇关于将一个命名空间添加到已配置的EntityManager中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆