title: Error: Method Doctrine\ORM\Query\Expr\From::__toString() must not throw an exception In symfony 2 application
body: <blockquote>
    <p>Pls i need to fetch the product entity based on the department it belong to but the department entity does not have a direct relationship with the product entity. Product is the great grand child of department in this manner
    DEPARTMENT-> CATEGORY-> GROUP-> PRODUCT.</p>
  </blockquote>
  
  <p>DepartmentRepository</p>
  
  <pre><code>public function findDepartmentProduct($id)
  {
      return $this
          -&gt;createQueryBuilder(['p', 'c', 'gc', 'ggc'])
          -&gt;select(['p', 'c', 'gc', 'ggc'])
          -&gt;from('Parent', 'p')
          -&gt;leftJoin('p.children', 'c')
          -&gt;leftJoin('c.grandchildren', 'gc')
          -&gt;leftJoin('gc.greatgrandchildren', 'ggc')
          -&gt;where('p.id = :id')
          -&gt;andWhere('ggc.expire = :no')
          -&gt;setParameter('no',0)
          -&gt;setParameter('id', $id)
          -&gt;getQuery();
     }
  </code></pre>
  
  <p>CONTROLLER:</p>
  
  <pre><code>  /**
   * @Route("/department/{id}", name = "department")
   */
  public function departmentAction(Request $request,$id)
  {
      $Department = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Department');
      $department = $Department-&gt;find($id);
  
      $Product = $this-&gt;getDoctrine()-&gt;getRepository('AppBundle:Product');
      $customersChoiceProducts = $Product-&gt;mostView('20');
  
  
      $query = $Department-&gt;findDepartmentProduct($id);
  
      $paginator  = $this-&gt;get('knp_paginator');
      $pagination = $paginator-&gt;paginate(
          $query, /* query NOT result */
          $request-&gt;query-&gt;getInt('page', 1)/*page number*/,
          8/*limit per page*/
      );
  
      return $this-&gt;render('default/department.html.twig', array(
          'pagination' =&gt; $pagination,
          'department'=&gt;$department,
          'customersChoiceProducts'=&gt;$customersChoiceProducts,
      ));
  }
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;div class="link"&gt;
                  &lt;ul&gt;
                      {% for product in pagination %}
                                  &lt;li &gt;
                                    &lt;a href="/brows/{{ product.id }}"&gt;
                                         &lt;span&gt;  &lt;img src="{{ vich_uploader_asset(product, 'frontImageFile') }}" alt="" style="height:290px"&gt;&lt;/span&gt;
                                         &lt;h2 class="title"&gt;
                                             &lt;span class="brand"&gt;{{ product.brand.name |title}}&lt;/span&gt;
                                             &lt;span class="name"&gt;{{ product.name|title }}&lt;/span&gt;
                                         &lt;/h2&gt;
                                          &lt;span class="price-box"&gt;
                                              &lt;span&gt;
                                                  &lt;span data-currency-iso="NGN"&gt;₦&lt;/span&gt;
                                                  &lt;span data-price="{{ product.price }}"&gt;{{ product.price }}&lt;/span&gt;
                                              &lt;/span&gt;
                                          &lt;/span&gt;
                                    &lt;/a&gt;
                                  &lt;/li&gt;
                      {% endfor %}
                  &lt;/ul&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>then i run the code i get error</p>
  
  <blockquote>
    <p>Error: Method Doctrine\ORM\Query\Expr\From::__toString() must not throw an exception
    500 Internal Server Error - FatalErrorException </p>
  </blockquote>