title: How to reopen Doctrine Entity Manager after DBALException
body: <p>I have a console application with Symfony 2, the script run on cron (terminal). But, after \Doctrine\DBAL\DBALException the script throw N \Doctrine\ORM\ORMException with message "The EntityManager is closed.". </p>
  
  <p>This is partial of script:</p>
  
  <pre><code>try {
  
      $this-&gt;getDoctrine()-&gt;getConnection()-&gt;beginTransaction();
  
      // ...
  
      $manager = $this-&gt;getDoctrine()-&gt;getManager();
  
      $entity = new Post();
      $entity
          -&gt;setAuthor($author)
          -&gt;setTitle($title)
          -&gt;setContent($content)
      ;
  
      $manager-&gt;persist($entity);
      $manager-&gt;flush();
  
      $this-&gt;getDoctrine()-&gt;getConnection()-&gt;commit();
  
      return $entity-&gt;getId();
  
  } catch (\Doctrine\DBAL\DBALException $e) {
  
      $this-&gt;getDoctrine()-&gt;resetManager();
  
      $output-&gt;writeln(sprintf(
          '&lt;error&gt;[!] %s (%s) the post could not be created "%s"&lt;/error&gt;',
          get_class($e),
          date('Y-m-d H:i:s'),
          $e-&gt;getMessage()
      ));
  
      return false;
  
  } catch (\Exception $e) {
  
      $this-&gt;getDoctrine()-&gt;getConnection()-&gt;rollback();
  
      $output-&gt;writeln(sprintf(
          '&lt;error&gt;[!] %s (%s) the post could not be created "%s"&lt;/error&gt;',
          get_class($e),
          date('Y-m-d H:i:s'),
          $e-&gt;getMessage()
      ));
  
      return false;
  }
  </code></pre>
  
  <p>How to fix it?</p>