title: Symfony 2 : how to override repository of another bundle
body: <p>I have 2 bundles and i want to override the repository of one of them in the other :</p>
  
  <p>I have a source bundle : SourceBundle. 
  I have my override bundle : OverrideBundle</p>
  
  <p>First, in OurVendorOverrideBundle.php, I added :</p>
  
  <pre><code>public function getParent()
  {
      return 'SomeVendorSourceBundle';
  }
  </code></pre>
  
  <p>Then </p>
  
  <p>I wanted to add a custom method for the repository of an entity of  SourceBundle.
  The source entity is Response.php, and its repository is ResponseRepository.php</p>
  
  <p>So i did : </p>
  
  <pre><code>&lt;?php
  namespace OurVendor\OverrideBundle\Repository;
  use Doctrine\ORM\EntityRepository;
  use SomeVendor\SourceBundle\Repository\ResponseRepository as BaseRepository;
  
  class ResponseRepository extends BaseRepository
  {
      /**
       *
       * @return array
       */
      public function getQueryExerciseAllResponsesForAllUsers($exoId)
      {
          $qb = $this-&gt;createQueryBuilder('r');
          $qb-&gt;join('r.paper', 'p')
              -&gt;join('p.exercise', 'e')
              -&gt;where('e.id = ?1')
              -&gt;andWhere('p.interupt =  ?2')
              -&gt;setParameters(array(1 =&gt; $exoId, 2 =&gt; 0));
          return $qb-&gt;getQuery();
      }
  }
  </code></pre>
  
  <p>If i dont set the Entity in the OverrideBundle i have this error :</p>
  
  <pre><code>The autoloader expected class "CPASimUSante\ExoverrideBundle\Entity\Response" to be defined in file "/home/www/myproject/vendor/ourvendor/override-bundle/OurVendor/OverrideBundle/Entity/Response.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
  </code></pre>
  
  <p>The SourceBundle entity is :</p>
  
  <pre><code>&lt;?php
  namespace SomeVendor\SourceBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  /**
   * SomeVendor\SourceBundle\Entity\Response
   *
   * @ORM\Entity(repositoryClass="SomeVendor\SourceBundle\Repository\ResponseRepository")
   * @ORM\Table(name="source_response")
   */
  class Response
  {
    ... 
  }
  </code></pre>
  
  <p>So i add the Entity in the OverrideBudle :</p>
  
  <pre><code>&lt;?php
  namespace OurVendor\OverrideBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  use SomeVendor\SourceBundle\Entity\Response as BaseEntity;
  /**
   * SomeVendor\SourceBundle\Entity\Response
   *
   * @ORM\Entity(repositoryClass="OurVendor\OverrideBundle\Repository\ResponseRepository")
   * @ORM\Table(name="override_response")
   */
  class Response extends BaseEntity
  {
      public function __construct()
      {
          parent::__construct();
      }
  }
  </code></pre>
  
  <p>But then i have this error :</p>
  
  <pre><code>An exception occurred while executing 'SELECT u0_.id AS id0, u0_.ip AS ip1, u0_.mark AS mark2, u0_.nb_tries AS nb_tries3, u0_.response AS response4, u0_.paper_id AS paper_id5, u0_.interaction_id AS interaction_id6 FROM ujm_exoverride_response u1_ INNER JOIN ujm_paper u2_ ON u0_.paper_id = u2_.id INNER JOIN ujm_exercise u3_ ON u2_.exercise_id = u3_.id WHERE u3_.id = ? AND u2_.interupt = ?' with params ["1", 0]:
  
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'u0_.id' in 'field list'
  </code></pre>
  
  <p>This seems that fields in the table are not found. So i changed to </p>
  
  <pre><code>&lt;?php
  namespace OurVendor\OverrideBundle\Entity;
  use Doctrine\ORM\Mapping as ORM;
  use SomeVendor\SourceBundle\Entity\Response as BaseEntity;
  /**
   * SomeVendor\SourceBundle\Entity\Response
   *
   * @ORM\Entity(repositoryClass="OurVendor\OverrideBundle\Repository\ResponseRepository")
   * @ORM\Table(name="source_response")
   */
  class Response extends BaseEntity
  {
      public function __construct()
      {
          parent::__construct();
      }
  }
  </code></pre>
  
  <p>And it worked.</p>
  
  <p>...But when i reinstalled the bundle, to test if everything was ok i had this <strong>fatal error</strong> stating that <strong>source_response is already defined</strong> (which is, indeed).</p>
  
  <p>So what can i do then ? </p>
  
  <p>I have also read that i can't override an entity unless the source extends MappedSuperclass, in my case, it doesn't. </p>
  
  <p>But i am doomed if i only want to override its repository ? Is it possible ? If then, what is the right way ?</p>
  
  <p>If i remove altogether the annotation for the override entity, i have  :</p>
  
  <pre><code>Class "OurVendor\OverrideBundle\Entity\Response" sub class of "SomeVendor\SourceBundle\Entity\Response" is not a valid entity or mapped super class.
  500 Internal Server Error - MappingException
  </code></pre>