haxpanel
haxpanel

Reputation: 4678

Add a namespace to an already configured EntityManager

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

Answers (1)

haxpanel
haxpanel

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

Related Questions