@@ -9,6 +9,8 @@ application. This is necessary if you are using different databases or even
99vendors with entirely different sets of entities. In other words, one entity
1010manager that connects to one database will handle some entities while another
1111entity manager that connects to another database might handle the rest.
12+ It is also possible to use multiple entity managers to manage a common set of
13+ entities, each with their own database connection strings or separate cache configuration.
1214
1315.. note ::
1416
@@ -44,7 +46,6 @@ The following configuration code shows how you can configure two entity managers
4446 driver : ' pdo_mysql'
4547 server_version : ' 5.7'
4648 charset : utf8mb4
47-
4849 orm :
4950 default_entity_manager : default
5051 entity_managers :
@@ -183,7 +184,7 @@ In this case, you've defined two entity managers and called them ``default``
183184and ``customer ``. The ``default `` entity manager manages entities in the
184185``src/Entity/Main `` directory, while the ``customer `` entity manager manages
185186entities in ``src/Entity/Customer ``. You've also defined two connections, one
186- for each entity manager.
187+ for each entity manager, but you are free to define the same connection for both .
187188
188189.. caution ::
189190
@@ -290,4 +291,26 @@ The same applies to repository calls::
290291 }
291292 }
292293
294+ .. caution ::
295+
296+ One entity can be managed by more than one entity manager. This however
297+ results in unexpected behavior when extending from ``ServiceEntityRepository ``
298+ in your custom repository. The ``ServiceEntityRepository `` always
299+ uses the configured entity manager for that entity.
300+
301+ In order to fix this situation, extend ``EntityRepository `` instead and
302+ no longer rely on autowiring::
303+
304+ // src/Repository/CustomerRepository.php
305+ namespace App\Repository;
306+
307+ use Doctrine\ORM\EntityRepository;
308+
309+ class CustomerRepository extends EntityRepository
310+ {
311+ // ...
312+ }
313+
314+ You should now always fetch this repository using ``ManagerRegistry::getRepository() ``.
315+
293316.. _`several alternatives` : https://stackoverflow.com/a/11494543
0 commit comments