title: Doctrine: Avoid duplicates in same insert process
body: <p>Is there a built in way / recommendation to handle duplicate entries while entities are inserted without a flush for each entry?</p>
  
  <p>Lets assume we have a person entity with two fields. ID and personalNr.
  ID is the primary key but personalNr has also a unique constraint.</p>
  
  <p>Now i am iterating over a csv file where one personalNr can be listed in multiple rows.</p>
  
  <p>If the row contains a personalNr, I check against the repository if a entry with this personalNr exist. If yes, i link the dataset to the person with the personalNr. If no, i create a new person with the personalNr and link it afterwards with the dataset.</p>
  
  <p>The problem now is:</p>
  
  <p>If a personalNr occurs more than once in a csv file, the dataset already exists in the entity manager when i find it again, but its unsaved to the database yet (i called no flush until now). The check against the repository will say "There is no entity in the repository" but the entity manager will throw an duplicate entry exception on flush cause it tries to create multiple entities with the same personalNr. </p>
  
  <p>How to avoid this? Is the only way to save what was already inserted or not by myself? Has doctrine such a checking mechanism?</p>
  
  <p>Thanks</p>