title: Repository method not always giving the expected results
body: <p>I have a weird Symfony/Doctrine bug. 
  My entities structure goes like this</p>
  
  <pre><code>class ClassA {
  
  /**
  * @ORM\ManyToOne(targetEntity="My\CoreBundle\Entity\ClassB", inversedBy="classAs", cascade={"persist"})
  * @ORM\JoinColumn(nullable=false)
  */
  private $classB;
  
  }
  
  class ClassB {
  
  /**
   * @ORM\OneToMany(targetEntity="My\CoreBundle\Entity\ClassA", mappedBy="classB", cascade={"persist", "remove"})
   */
  private $classAs;
  
  /**
  * @ORM\ManyToOne(targetEntity="My\CoreBundle\Entity\ClassC", inversedBy="classBs")
  * @ORM\JoinColumn(nullable=false)
  */
  private $classC;
  
  }
  
  class ClassC {
  
  /**
  * Inverse Side
  * @ORM\OneToMany(targetEntity="My\CoreBundle\Entity\ClassB", mappedBy="classC", cascade={"persist", "remove"})
  */
  private $classBs;
  
  /**
  * Inverse Side
  * @ORM\OneToMany(targetEntity="My\CoreBundle\Entity\ClassD", mappedBy="classCs", cascade={"persist", "remove"})
  */
  private $classDs;
  
  }
  
  class ClassD {
  
  /**
  * @ORM\ManyToOne(targetEntity="My\CoreBundle\Entity\ClassC", inversedBy="classDs")
  * @ORM\JoinColumn(nullable=false)
  */
  private $classC;
  
  }
  </code></pre>
  
  <p>I know that in the database that ClassA (id=566208) is linked to ClassD (id=16286).</p>
  
  <p>I have this very simple method in ClassARepository.</p>
  
  <pre><code>class ClassARepository extends EntityRepository
  {
      public function myMethod()
      {
          $builder = $this-&gt;createQueryBuilder('classA');
          $query = $builder-&gt;getQuery();
  
          $classAs = $query-&gt;getResult();
  
          echo "&lt;pre&gt;";
          foreach ($classAs as $classA) {
              if ($classA-&gt;getId() == 566208)
              {
                  echo "classA 566208\n";
                  $classDs = $classA-&gt;getClassB()-&gt;getClassC()-&gt;getClassDs();
                  $found = false;
                  foreach ($classDs as $classD) {
                      if (16286 == $classD-&gt;getId()) {
                              $found = true;
                              echo "INFO 16286 found\n";
                      }
                  }
                  if (false == $found) echo "ERROR 16286 Not found\n";
              }
          }
          echo "&lt;/pre&gt;";
    }
  }
  </code></pre>
  
  <p>When I call this method in a controller no problem</p>
  
  <pre><code>class MyController
  {
      public function indexAction()
      {
          $this-&gt;getRepository('MyCoreBundle:ClassA')-&gt;myMethod();
  
      // [...]
      }
  }
  </code></pre>
  
  <p>Result is</p>
  
  <pre><code>classA 566208
  INFO 16286 found
  </code></pre>
  
  <p>But in an other part of the code</p>
  
  <pre><code>class MyService
  {
      private function myServiceMethod()
      {
          $this-&gt;doctrine-&gt;getManager()
                          -&gt;getRepository('MyCoreBundle:ClassA')-&gt;myMethod();
      }
  }
  </code></pre>
  
  <p>Result is</p>
  
  <pre><code>classA 566208
  ERROR 16286 Not found
  </code></pre>
  
  <p>What can cause this? I a bit confused and don't know if my Doctrine is reliable.</p>
  
  <p>My config 
      "php" : ">=5.5",
      "symfony/symfony" : "2.8.*",
      "doctrine/orm" : "~2.5",</p>
  
  <p>I did a MySQLcheck everything seems ok.</p>
  
  <p><strong>EDIT/TLDR:</strong></p>
  
  <p>This code...</p>
  
  <pre><code>echo "&lt;pre&gt;";
  echo "NORMAL\n";
  $classC = $this-&gt;doctrine-&gt;getManager()-&gt;getRepository('MyCoreBundle:ClassC')-&gt;find(7);
  $classDs = $classC-&gt;getClassDs();
  $found = false;
  foreach ($classDs as $classD) {
      if (16286 == $classD-&gt;getId()) {
              $found = true;
              echo "INFO 16286 found\n";
      }
  }
  if (false == $found) echo "ERROR 16286 Not found\n";
  
  echo "INVERSED\n";
  $classDs = $this-&gt;doctrine-&gt;getManager()-&gt;getRepository('MyCoreBundle:ClassD')-&gt;findBy(array("classC" =&gt; 7));
  $found = false;
  foreach ($classDs as $classD) {
      if (16286 == $classD-&gt;getId()) {
              $found = true;
              echo "INFO 16286 found\n";
      }
  }
  if (false == $found) echo "ERROR 16286 Not found\n";
  echo "&lt;/pre&gt;";
  </code></pre>
  
  <p>...gives...</p>
  
  <pre><code>NORMAL
  ERROR 16286 Not found
  INVERSED
  INFO 16286 found
  </code></pre>