title: When to use Entity Manager in Symfony2
body: <p>At the moment I am learning how to use Symfony2. I got to the point where they explain how to use Doctrine.</p>
  
  <p>In the examples given they sometimes use the entity manager:</p>
  
  <pre><code>$em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  $products = $em-&gt;getRepository('AcmeStoreBundle:Product')
          -&gt;findAllOrderedByName();
  </code></pre>
  
  <p>and in other examples the entity manager is not used: </p>
  
  <pre><code>$product = $this-&gt;getDoctrine()
          -&gt;getRepository('AcmeStoreBundle:Product')
          -&gt;find($id);
  </code></pre>
  
  <p>So I actually tried the first example without getting the entity manager:</p>
  
  <pre><code>$repository = $this-&gt;getDoctrine()
          -&gt;getRepository('AcmeStoreBundle:Product');
  $products = $repository-&gt;findAllOrderedByName();
  </code></pre>
  
  <p>and got the same results.</p>
  
  <p>So when do i actually need the entity manager and when is it OK to just go for the repository at once?</p>