From 014b19040c90184633fb308b47d4b2500a4d3008 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 3 May 2011 07:32:16 +0200 Subject: [PATCH] [DoctrineBundle] changed the Registry to return a new instance if the current em is closed $em = $this->get('doctrine')->getEntityManager(); $em->getConnection()->beginTransaction(); // suspend auto-commit try { //... do some work } catch (Exception $e) { $em->getConnection()->rollback(); $em->close(); // get a new EM $em = $this->get('doctrine')->getEntityManager(); } --- src/Symfony/Bundle/DoctrineBundle/Registry.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/DoctrineBundle/Registry.php b/src/Symfony/Bundle/DoctrineBundle/Registry.php index 2832dae518ff..f677a52a2e67 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Registry.php +++ b/src/Symfony/Bundle/DoctrineBundle/Registry.php @@ -103,7 +103,16 @@ public function getEntityManager($name = null) throw new \InvalidArgumentException(sprintf('Doctrine EntityManager named "%s" does not exist.', $name)); } - return $this->container->get($this->entityManagers[$name]); + $em = $this->container->get($this->entityManagers[$name]); + + if (!$em->isOpen()) { + // force the creation of a new entity manager + // if the current one is closed + $this->container->set($this->entityManagers[$name], null); + $em = $this->container->get($this->entityManagers[$name]); + } + + return $em; } /**