I am registering Doctrine in Silex in this way:
// Doctrine
$this->register(new DoctrineServiceProvider(), array(
'db.options' => $this['config']['doctrine']['db.options']
));
$this->register(new DoctrineOrmServiceProvider());
$this['orm.em.options'] = $this['config']['doctrine']['orm.em.options'];
If I insert a duplicated row then I get this exception:
Integrity constraint violation: 1062 Duplicate entry
I have catched this exception using try/catch. If later I try to use again Doctrine, now always this exception is shown:
The EntityManager is closed.
If I try reload the EntityManager following these steps (The EntityManager is closed) :
if (!$app['orm.em']->isOpen()) {
$app['orm.em'] = $app['orm.em']->create(
$app['orm.em']->getConnection(), $app['orm.em']->getConfiguration(), $app['orm.em']->getEventManager()
);
}
But now this exception is shown:
Cannot override frozen service "orm.em"
How can I use Doctrine provider in Silex after a Doctrine exception is happened?
Thanks.