title: Custom repository problems with Symfony2 - Notice: Undefined offset: 0
body: <p>I'm trying to move my query into a custom repository class. Here is what I've got so far</p>
  
  <pre><code>class MovieRepository extends EntityRepository
  {
      public function showMovie($movie)
      {
      $em = $this-&gt;getEntityManager();
  
      $qb = $em-&gt;createQueryBuilder('m');
  
      $query = $qb-&gt;select('m.title', 'm.img', 'u.username')
          -&gt;where('m.title = :movie')
          -&gt;leftJoin('m.user', 'u')
          -&gt;setParameter('movie', $movie)
          -&gt;getQuery();
  
      return $query-&gt;getSingleResult();
      }
  }
  </code></pre>
  
  <p>I use it like this in my controller:</p>
  
  <pre><code>$em = $this-&gt;getDoctrine()-&gt;getManager();
  $result = $em-&gt;getRepository('AMovieBundle:Movie')-&gt;showMovie($movie);
  </code></pre>
  
  <p>I did put the @ORM\Entity(repositoryClass="A\MovieBundle\Entity\MovieRepository") in my entity and the namespaces and folders are correct, and my relations from the movie to the user is correct as this worked before, when I had the query in the controller.</p>
  
  <p>The primary error I keep getting is this:</p>
  
  <blockquote>
    <p>Notice: Undefined offset: 0 in /Applications/MAMP/htdocs/symfony2test/vendor/doctrine/orm/lib/Doctrine/ORM/QueryBuilder.php line 271</p>
  </blockquote>
  
  <p>Line 271 in the query builder is this:</p>
  
  <pre><code>public function getRootAlias()
  {
      $aliases = $this-&gt;getRootAliases();
      return $aliases[0];
  }
  </code></pre>
  
  <p>I have no idea where to go from here and any help would be greatly appreciated.</p>