New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with multiple entity managers #921
Comments
This issue was transferred from Doctrine ORM with an unsupported 2.5 version Can you please try to recreate this behaviour with the newest DoctrineBundle and a current ORM version? |
Important information to begin with: your entity should only be registered with one entity manager, not multiple ones. The
So, if your entity class is registered with multiple entity managers, the repository will always use the first entity manager that matches. I don't know your use-case, but I don't see a reason why you should have multiple entity managers in charge of the same entity class, that just leads to problems eventually. Note that you don't have to extend |
Hello @alcaeus, Thank you a lot for your reply! My use case is the following: I synchronize two versions of the same database. Each version is managed by its own entity manager. Do you have any suggestion regarding how to achive this "the right way"? Thank you again! Fabien |
Don't extend |
@alcaeus sorry I don't understand. If I do that, that means the repository is dedicated to only one of my two entity managers. I want it to be usable for both. I do such things:
Fabien |
You'll need to:
Automatically creating a service for this repository (via a service prototype) won't work as that will only create a single repository which will only be registered in the repository factory for one entity manager. |
Ok that's bad news as it involves a signifiant refactoring effort. Thank you again for your help! Kind regards! |
Bug Report
With multiple entity managers dealing with same entities, repository objects always use the default entity manager.
Summary
I have two entity managers in order to synchronise two databases that share the same schema.
Let's say I have the following managers:
$entityManager1
and$entityManager2
.When my repository class extends
Doctrine\ORM\EntityRepository
:$entityManager1->findAll()
and$entityManager2->findAll()
work as expected.But when my repository class extends
Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository
, both$entityManager1->findAll()
and$entityManager2->findAll()
perform query on the$entityManager1
managed database.I need to extend
Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository
in order to allow services injection:Do you have any hints to solve this issue?
Thank you.
The text was updated successfully, but these errors were encountered: