title: How to get the EntityManager in Symfony 3, correctly?
body: <p>I am using current versions of Symfony (3.2.3) and Doctrine ORM (2.5.6) and I'm still trying to wrap my head around how to handle the deprecation of <code>getEntityManager()</code> and related methods <em>correctly</em>.</p>
  
  <p>For instance, the current <a href="http://symfony.com/doc/current/doctrine.html" rel="noreferrer">documentation</a> states that this is the way to create a query builder instance:</p>
  
  <pre><code>$repository = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Product');
  $queryBuilder = $repository-&gt;createQueryBuilder('p')
  </code></pre>
  
  <p>But the way I see it (and my IDE seems to agree), <code>getRepository()</code> is type hinted to return an instance of <code>ObjectRepository</code> and the method <code>createQueryBuilder()</code> is not declared in that interface but in the implementing class <code>EntityRepository</code>.</p>
  
  <p>An other example would be explicitly starting a transaction in a controller:</p>
  
  <pre><code>$this-&gt;getDoctrine()-&gt;getEntityManager()-&gt;getConnection()-&gt;beginTransaction()
  </code></pre>
  
  <p>I'm supposed to call <code>getManager()</code> instead of <code>getEntityManager()</code> because the latter method is deprecated. But <code>getManager()</code> is type hinted to return an instance of <code>ObjectManager</code> which does not declare <code>getConnection()</code>.</p>
  
  <p>PHP being PHP the code still seems to be working in all cases, but my IDE and I are left with an uneasy feeling. So, what is the <em>correct</em> way to create a query builder or begin a transaction in Symfony 3? Am I missing something?</p>