title: Symfony2: get the id of the persisted object
body: <p>I have two entity: User and Person.</p>
  
  <p>In the entity User I need the id of the associated person: user_id.</p>
  
  <p>When I am creating a new user, I have to create first the person and then the user.
  In the user, I have to put the id of the corresponding person and for that I need to get the id of the persisted object person which is an auto increment.</p>
  
  <p>Is it possible to get the id of the object after:</p>
  
  <pre><code>$em-&gt;persist($person);
  $em-&gt;flush();
  </code></pre>
  
  <p>And how can I do this?</p>
  
  <p>The alternative is to search the biggest id it the table Person and take this one but I think there should be a better and easier method to get the id of the persisted object.</p>
  
  <p>In php for example, when I execute</p>
  
  <pre><code>$articleID = $_DB-&gt;queryRaw((....);
  </code></pre>
  
  <p>I am getting the id like that.</p>