title: Doctrine entity manager using wrong connection
body: <p>According to the <a href="https://symfony.com/doc/current/doctrine/multiple_entity_managers.html" rel="nofollow noreferrer">Symfony docs</a>, multiple entity managers can be configured by listing them in <code>config/packages/doctrine.yaml</code> then selecting a specific entity manager in a controller like this: <code>$this-&gt;getDoctrine()-&gt;getManager('customer');</code>.</p>
  
  <p>I set up my <code>config/packages/doctrine.yaml</code>:</p>
  
  <pre><code>doctrine:
      dbal:
          default_connection: default
          connections:
              default:
                  # configure these for your database server
                  url: '%env(DATABASE_URL)%'
                  driver: 'pdo_mysql'
                  server_version: '8.0'
                  charset: utf8mb4
              meter:
                  # configure these for your database server
                  url: '%env(DATABASE_METER_URL)%'
                  driver: 'pdo_mysql'
                  server_version: '8.0'
                  charset: utf8mb4
  
      orm:
          default_entity_manager: default
          entity_managers:
              default:
                  connection: default
                  naming_strategy: doctrine.orm.naming_strategy.underscore
                  mappings:
                      App:
                          is_bundle: false
                          type: annotation
                          dir: '%kernel.project_dir%/src/Entity'
                          prefix: 'App\Entity'
                          alias: App
              meter:
                  connection: meter
                  naming_strategy: doctrine.orm.naming_strategy.underscore
                  mappings:
                      App:
                          is_bundle: false
                          type: annotation
                          dir: '%kernel.project_dir%/src/Entity'
                          prefix: 'App\Entity'
                          alias: App
  </code></pre>
  
  <p>and then tried to make a query with </p>
  
  <pre class="lang-php prettyprint-override"><code>$meterEntityManager = $this-&gt;getDoctrine()-&gt;getManager('meter');
  $meter = $meterEntityManager-&gt;getRepository(Entity\Meter::class)-&gt;find($meterId);
  </code></pre>
  
  <p>However, the result of <code>$meterEntityManager-&gt;getRepository(Entity\Meter::class)-&gt;find($meterId)</code> is a row from the database connection named <code>default</code>, not the one named <code>meter</code> -- it is as if the code had been</p>
  
  <pre class="lang-php prettyprint-override"><code>$entityManager = $this-&gt;getDoctrine()-&gt;getManager('default');
  $meter = $entityManager-&gt;getRepository(Entity\Meter::class)-&gt;find($meterId);
  </code></pre>
  
  <p>When I check the connection with <code>$meterEntityManager-&gt;getConnection()-&gt;getParams()</code> it correctly lists the params for the <code>meter</code> connection rather than the <code>default</code> connection, so I can get a row from the <code>meter</code> database connection by executing queries directly on the connection object:</p>
  
  <pre class="lang-php prettyprint-override"><code>$meterEntityManager = $this-&gt;getDoctrine()-&gt;getManager('meter');
  $stmt = $meterEntityManager-&gt;getConnection()-&gt;prepare('SELECT * FROM meter WHERE id = :id');
  $stmt-&gt;execute(['id' =&gt; $meterId]);
  $meter = $stmt-&gt;fetch();
  </code></pre>
  
  <p>But ultimately I want to fetch rows through the methods offered by <code>getRepository(Entity\Meter::class)</code> so returned data is automatically hydrated into doctrine entities. There seems to be an inconsistency between the connection used by <code>$meterEntityManager-&gt;getRepository(Entity\Meter::class)</code> and <code>$meterEntityManager-&gt;getConnection()</code>. Why is this? Does it have something to do with the entity managers using different connections but sharing the same mappings to entities?</p>