Skip to content

Commit

Permalink
[DoctrineBundle] changed the Registry to return a new instance if the…
Browse files Browse the repository at this point in the history
… 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();
    }
  • Loading branch information
fabpot committed May 3, 2011
1 parent bd608c8 commit 014b190
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Symfony/Bundle/DoctrineBundle/Registry.php
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 014b190

Please sign in to comment.