DDC-2156: [regression] EntityManager::find() doesn't call custom repository anymore #2712

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

Originally created by @doctrinebot on GitHub (Nov 19, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user literal:

Up to version 2.2 the entity manager would forward calls to find() to the respective repositories. In 2.3 the entity manager handles these calls directly.

This interferes with custom repositories that have an overridden find() method.

It's inconsistent, because $em->getRepository('Foo')->find($id) may do something different to $em ->find('Foo', $id) now.

Not sure if this is intentional. If it is, it's missing in the change log and the docs (7.8.1. "Essentially, EntityManager#find() is just a shortcut for the following...").

In any case it's a big BC issue for us:

  • We have (generated) repositories for all aggregate roots which override find() to throw (also generated) custom exceptions when an entity isn't found. We just don't want all those null checks in the client code, especially as we'd sooner or later forget one somewhere.
  • We are using the $em->find('Foo', $id) style everywhere because it's more concise - it doesn't seem to make much sense to explicitly fetch the repository when this could be done implicitly.
Originally created by @doctrinebot on GitHub (Nov 19, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user literal: Up to version 2.2 the entity manager would forward calls to `find()` to the respective repositories. In 2.3 the entity manager handles these calls directly. This interferes with custom repositories that have an overridden `find()` method. It's inconsistent, because `$em->getRepository('Foo')->find($id)` may do something different to `$em ->find('Foo', $id)` now. Not sure if this is intentional. If it is, it's missing in the change log and the docs (7.8.1. "Essentially, EntityManager#find() is just a shortcut for the following..."). In any case it's a big BC issue for us: - We have (generated) repositories for all aggregate roots which override `find()` to throw (also generated) custom exceptions when an entity isn't found. We just don't want all those `null` checks in the client code, especially as we'd sooner or later forget one somewhere. - We are using the `$em->find('Foo', $id)` style everywhere because it's more concise - it doesn't seem to make much sense to explicitly fetch the repository when this could be done implicitly.
admin added the Bug label 2026-01-22 14:01:15 +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#2712