title: Argument passed to __construct() expected to be SomeRepository, instance of EntityRepository instead
body: <p>I've defined my custom repositories according to the <a href="http://symfony.com/doc/current/doctrine/repository.html" rel="nofollow noreferrer">symfony docs</a> and followed this <a href="https://php-and-symfony.matthiasnoback.nl/2014/05/inject-a-repository-instead-of-an-entity-manager/" rel="nofollow noreferrer">blog post</a> to define them as a service. This normally works fine, except sometimes I get the exception:</p>
  
  <blockquote>
    <p>FatalThrowableError in SomeService.php line 20: Type error: Argument 3
    passed to SomeService::__construct() must be an instance of
    SomeRepository, instance of Doctrine\ORM\EntityRepository
    given, called in var/cache/dev/appDevDebugProjectContainer.php on line
    7651</p>
  </blockquote>
  
  <p>This happens quite a lot, and normally clearing the cache and the doctrine metadata cache solves it. But sometimes it doesn't. </p>
  
  <pre><code>php app/console cache:clear
  php app/console doctrine:cache:clear-metadata
  </code></pre>
  
  <p>I don't actually understand why this happens or how to fix it in the times that clearing the cache doesn't work. I know that this question (or derivative of it) has been asked a lot, like <a href="https://stackoverflow.com/q/17228417/1393498">here</a>, <a href="https://stackoverflow.com/q/24809566/1393498">here</a>, <a href="https://stackoverflow.com/q/38542747/1393498">here</a>, <a href="https://stackoverflow.com/q/28154975/1393498">here</a> and <a href="https://stackoverflow.com/q/9248684/1393498">here</a>. But none of those answers actually solves my problem, because as far as I can see I've defined everything correctly, also we have a bunch of other repositories defined exactly the same way and they all work fine.</p>
  
  <pre class="lang-yaml prettyprint-override"><code># services.yml
  app.repository.some:
      class: AppBundle\Repository\SomeRepository
      factory: ["@doctrine.orm.default_entity_manager", getRepository]
      arguments:
          - AppBundle\Entity\Some
  
  app.some_service:
      class: AppBundle\Services\SomeService
      arguments:
          - "@app.repository.some"
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>// Repository class
  &lt;?php
  
  namespace AppBundle\Repository;
  
  use Doctrine\ORM\EntityRepository;
  
  class SomeRepository extends EntityRepository
  {
  
  }
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>// Entity class
  &lt;?php
  
  namespace AppBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass="AppBundle\Repository\SomeRepository")
   * @ORM\Table()
   * @ORM\Entity
   */
  class Some
  {
  </code></pre>
  
  <pre class="lang-php prettyprint-override"><code>// Service class
  &lt;?php
  
  namespace  AppBundle\Services;
  
  use AppBundle\Repository\SomeRepository;
  
  class NotificationService
  {
      /** @var SomeRepository */
      protected $someRepository;
  
      public function __construct(
          SomeRepository $someRepository,
      ) {
  </code></pre>
  
  <p>Is there some other cache that needs to be cleared or something I'm missing?</p>