title: Undefined method 'getDoctrine'. The method name must start with either findBy or findOneBy
body: <p>I am currently working with Symfony2 and I am getting this ERROR message:</p>
  
  <p>Undefined method 'getDoctrine'. The method name must start with either findBy or findOneBy!
  500 Internal Server Error - BadMethodCallException</p>
  
  <p>This is my Entity Class:</p>
  
  <pre><code> &lt;?php
  
  namespace Gestionresiduos\ResiduoBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * @ORM\Entity(repositoryClass="ResiduoRepository")
  */
  
  class BodegaContieneResiduo
  {
  
  
      /**
      * @ORM\Id
      * @ORM\column(type="integer")
      * @ORM\GeneratedValue
      */
  
      protected $idContiene;
  
  .....
  
  }
  </code></pre>
  
  <p>This is the Controller's page Action method:</p>
  
  <pre><code> &lt;?php
  
  namespace Gestionresiduos\ResiduoBundle\Controller;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  
  class DefaultController extends Controller
  {
      public function portadaAction()
      {
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
  
          $ofertas= $em-&gt;getRepository('ResiduoBundle:BodegaContieneResiduo')-&gt;findResiduosAlmacenados();
          return $this-&gt;render('ResiduoBundle:Default:index.html.twig');
      }
  }
  </code></pre>
  
  <p>This is my EntityRepository:</p>
  
  <pre><code>    &lt;?php
  namespace Gestionresiduos\ResiduoBundle\Entity;
  
  use Doctrine\ORM\EntityRepository;
  
  class ResiduoRepository extends EntityRepository
  {
  
      public function findResiduosAlmacenados()
      {
          $em = $this-&gt;getDoctrine()-&gt;getEntityManager();
          $consulta = $em-&gt;createQuery('SELECT r FROM ResiduoBundle:BodegaContieneResiduo');
          return $consulta-&gt;getOneOrNullResult();
      }
  }
  </code></pre>
  
  <p>I also tried all solutions in this <a href="https://stackoverflow.com/questions/9172586/the-method-name-must-start-with-either-findby-or-findoneby-undefined-method-sym">post</a> by ScoRpion and this <a href="https://stackoverflow.com/questions/28873149/symfony2-undefined-method-the-method-name-must-start-with-either-findby-or-find">post</a> by K-Alex </p>
  
  <p>So, Where is THE PROBLEM ???</p>