title: Doctrine: How to get auto generated id after a merge ?
body: <p>I'm working on a legacy project in Symfony2, where mappings of entities are not correctly defined, but I would prefer not to touch them... </p>
  
  <p>I got an entity with several ManyToOne relationships, but no cascade persist has been defined on these associations. And the associated entities also have relationships, and so on (the project is quite big)... </p>
  
  <p>So, when I need to write a new entity to database, I usually use merge to avoid persisting all related entities: </p>
  
  <pre><code>$myObject = new Object();
  ...
  $em-&gt;merge($myObject);
  $em-&gt;flush();
  </code></pre>
  
  <p>But this time, I need to get the id of the inserted object. This id is auto generated by Doctrine (I also prefer not to change this).</p>
  
  <p>I know that with persist, I can do: </p>
  
  <pre><code>$em-&gt;persist($object);
  $em-&gt;flush();
  $id = $object-&gt;getId();
  </code></pre>
  
  <p>But how can I do with merge ? Obviously this won't work: </p>
  
  <pre><code>$em-&gt;merge($object);
  $em-&gt;flush();
  $id = $object-&gt;getId(); // $id is null... 
  </code></pre>
  
  <p>Thanks.</p>