Question: Why is Doctrine\ORM\EntityRepository#getEntityManager() protected? #5634

Open
opened 2026-01-22 15:13:20 +01:00 by admin · 0 comments
Owner

Originally created by @spackmat on GitHub (Aug 11, 2017).

Originally assigned to: @Ocramius on GitHub.

Hi,

I am refactoring my Symfony controllers to get the EntityRepositories injected instead of the whole EntityManager. This works fine, but in some cases (transactions, changing listeners etc.), I still need access to the EntityManager.

But the Doctrine\ORM\EntityRepository#getEntityManager() method is protected. This surely is intentional, so my question is: Would it be bad practice to access the EntityManager through (injected) repositories? Or are there other reasons for the protection?

Greets,
spackmat

Originally created by @spackmat on GitHub (Aug 11, 2017). Originally assigned to: @Ocramius on GitHub. Hi, I am refactoring my Symfony controllers to get the EntityRepositories injected instead of the whole EntityManager. This works fine, but in some cases (transactions, changing listeners etc.), I still need access to the EntityManager. But the Doctrine\ORM\EntityRepository#getEntityManager() method is protected. This surely is intentional, so my question is: Would it be bad practice to access the EntityManager through (injected) repositories? Or are there other reasons for the protection? Greets, spackmat
admin added the Question label 2026-01-22 15:13:20 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5634