title: Abstract repository and @Entity annotation inheritance
body: <p>I implement a custom <code>EntityRepository</code> in a Symfony2 application.</p>
  
  <p>I have an AbstractEntity (used as parent of some entities) :</p>
  
  <pre><code>/**
   * Abstract Entity.
   *
   * @ORM\Entity(repositoryClass="App\Util\Entity\AbstractRepository")
   */
  abstract class AbstractEntity
  {
      /**
       * Get id.
       *
       * @return int
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      // ...
  }
  </code></pre>
  
  <p>The custom <code>EntityRepository</code> :</p>
  
  <pre><code>/**
   * Abstract Repository.
   */
  class AbstractRepository extends Doctrine\ORM\EntityRepository
  {
      /**
       * Handles resource not found from find.
       *
       * @param int $id
       *
       * @return object
       */
      public function findOrFail($id)
      {
          if (null == $entity = $this-&gt;find($id)) {
              return $this-&gt;fail();
          }
  
          return $entity;
      }
  
     //...
  }
  </code></pre>
  
  <p>And one of the entities that extends from <code>AbstractEntity</code> :</p>
  
  <pre><code>/**
   * @ORM\Table(name="tags_sport")
   */
  class Tag extends AbstractEntity
  {
       // ...
  }
  </code></pre>
  
  <p>The custom repository is declared once in my AbstractEntity using <code>@ORM\Entity</code> annotation.<br>
  I want make my entities use the same repository without redeclare it.</p>
  
  <p>But an error occurs  :</p>
  
  <pre><code>Class "App\SportBundle\Entity\Tag" sub class of "App\Util\Entity\AbstractEntity" is not a valid entity or mapped super class
  </code></pre>
  
  <p>It's caused by the missing <code>@ORM\Entity</code> annotation in the child entity.  </p>
  
  <p>But nothing change.<br>
  If I add the <code>@ORM\Entity</code> annotation in the child entity, it will use the default <code>EntityRepository</code>.</p>
  
  <p>How can I override the default <code>EntityRepository</code> for each entities extending from the <code>AbstractEntity</code> ?</p>
  
  <p><strong>EDIT</strong> I accept @Rvanlaak answer thanks to a gist given in the answer comments.<br>
  The final solution including the whole custom Repository in <a href="https://gist.github.com/chalasr/77be8eee5e3ecd3c06ec" rel="nofollow">this gist</a></p>