title: How avoid closing EntityManager when OptimisticLockException occurs?
body: <p>My problem - process try change entity that already changed and have newest version id. When i do flush() in my code in UnitOfWork's commit() rising OptimisticLockException and catching in same place by catch-all block. And in this catch doctrine closing EntityManager. 
  If i want skip this entity and continue with another from ArrayCollection, i should not use flush()?</p>
  
  <p>Try recreate EntityManager:</p>
  
  <pre><code>}catch (OptimisticLockException $e){
      $this-&gt;em = $this-&gt;container-&gt;get('doctrine')-&gt;getManager();
      echo "\n||OptimisticLockException.";
      continue;
  }
  </code></pre>
  
  <p>And still get </p>
  
  <pre><code>[Doctrine\ORM\ORMException]   
  The EntityManager is closed.
  </code></pre>
  
  <p>Strange.</p>
  
  <p>If i do </p>
  
  <pre><code>$this-&gt;em-&gt;lock($entity, LockMode::OPTIMISTIC, $entity-&gt;getVersion());
  </code></pre>
  
  <p>and then do flush() i get OptimisticLockException and closed entity manager.
  if i do</p>
  
  <pre><code>$this-&gt;getContainer()-&gt;get('doctrine')-&gt;resetManager();
  $em = $doctrine-&gt;getManager();
  </code></pre>
  
  <p>Old data unregistered with this entity manager and i even can't write logs in database, i get error: </p>
  
  <pre><code>[Symfony\Component\Debug\Exception\ContextErrorException]  
  Notice: Undefined index: 00000000514cef3c000000002ff4781e
  </code></pre>