title: Doctrine2 $em->persist($entity) on foreach loop
body: <p>I'm currently in a spot, where I need to create or update entities in a foreach loop.</p>
  
  <p>So I'm doing the following (short code):</p>
  
  <pre><code>foreach ($dataset as $data) {
      $entity = new Entity();
  
      // ---- Some setting operations on the entity
  
      $em-&gt;persist($entity);
  }
  
  $em-&gt;flush();
  </code></pre>
  
  <p>The thing I was expecting is that Doctrine manages the entities and then with one statement inserts the entities into the table.</p>
  
  <p>But it occurs, that Doctrine makes one statement for each created entity.
  Since the $dataset array can be pretty big (a lot of entities created), I would like to have it packed into one statement.</p>
  
  <p>How can I achieve this?</p>