title: How to retry transaction after a deadlock using Doctrine?
body: <p>I am writing a PHP function which store/updates large sets of data into a table and that may cause a deadlock. I tried investigating how to retry a failed transaction with Doctrine but sadly could not find any info online. I eventually wrote the following code</p>
  
  <pre><code> $retry = 0;
   $done = false;
   while (!$done and $retry &lt; 3) {
       try {
  
           $this-&gt;entityManager-&gt;flush();
           $done = true;
  
       } catch (\Exception $e) {
           sleep(1);
  
           $retry++;
       }
   }
  
   if ($retry == 3) {
       throw new Exception(
           "[Exception: MySQL Deadlock] Too many people accessing the server at the same time. Try again in few minutes"
       );
   }
  </code></pre>
  
  <p><strong>My question:</strong> is there a chance this approach will insert duplicates in the database? if so, how can I force Doctrine to roll back the transactions?</p>