title: Unexpected behavior of doctrine entity manager
body: <p>I have a helper service that links me to a database on the fly.</p>
  
  <pre><code>$databaseName = 'db_x'; 
  
  $em = $this-&gt;entityManagerProvider-&gt;get($databaseName);
  </code></pre>
  
  <p>I can use this entity manager like this:</p>
  
  <pre><code>$car = new Car();
  $car-&gt;setName('Audi');
  
  $em-&gt;persist($car);
  $em-&gt;flush();
  </code></pre>
  
  <p>It works good! Object was inserted to my db_x</p>
  
  <p>But If I run repository method on this entity manager:</p>
  
  <pre><code>$em-&gt;getRepository('App\Entity\Car')-&gt;findById(1);
  </code></pre>
  
  <p>Then entity manager try run on my default database, not db_x. How it is possible?</p>
  
  <p>My service to switch database:</p>
  
  <pre><code>namespace App\Utils\Database;
  
  use Doctrine\ORM\EntityManager;
  use Doctrine\ORM\EntityManagerInterface;
  
  class EntityManagerProvider
  {
      /**
       * @var EntityManagerInterface
       */
      protected $entityManager;
  
      public function __construct(EntityManagerInterface $entityManager)
      {
          $this-&gt;entityManager = $entityManager;
      }
  
      /**
       * @param $databaseName
       * @return EntityManagerInterface
       * @throws \Doctrine\ORM\ORMException
       */
      public function get($databaseName): EntityManagerInterface
      {
          return EntityManager::create(
              $this-&gt;configureParams($databaseName),
              $this-&gt;entityManager-&gt;getConfiguration(),
              $this-&gt;entityManager-&gt;getEventManager()
          );
      }
  
      /**
       * @param string $databaseName
       * @return array
       */
      private function configureParams(string $databaseName): array
      {
          $params = $this-&gt;entityManager-&gt;getConnection()-&gt;getParams();
  
          unset(
              $params['dbname'],
              $params['path'],
              $params['url'],
              $params["wrapperClass"]
          );
  
          $params['dbname'] = $databaseName;
  
          return $params;
      }
  }
  </code></pre>