Reputation: 4678
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
Upvotes: 1
Views: 212
Reputation: 4678
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);
Upvotes: 1