Skip to content


DDC-834: EntityManager::getReference may return proxy for parent class when using class table inheritance #5354

doctrinebot opened this Issue · 2 comments

2 participants


Jira issue originally created by user pschwisow:

When using class table inheritance, it is possible for a parent class proxy to get saved into the identifier map.


 * @Entity
 * @InheritanceType("JOINED")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"employee" = "Employee", "customer" = "Customer"})
class Person

/*** @Entity **/
class Employee extends Person
    public function getEmployeeNumber()

The following will fail:

$person = $entityManager->getReference('Person', 1);  // the identity map contains a PersonProxy with id 1


$employee = $entityManger->getReference('Employee', 1);  // $employee is set to the PersonProxy object in the identity map


$employee->getEmployeeNumber();  // error, PersonProxy object does not have a getEmployeeNumber method

Comment created by @beberlei:

Fixed this issue. Classes that have further entity subclasses CANNOT be loaded by reference. This is a technical requirement. Go live with it inheritance users ;-)

Also updated the docs:

There is a general performance consideration with Single and Class Table Inheritance: If you use a STI/CTI entity as
a many-to-one or one-to-one entity you should never use one of the classes at the upper levels of the
inheritance hierachy as "targetEntity", only those that have no subclasses. Otherwise Doctrine **CANNOT**
create proxy instances of this entity and will **ALWAYS** load the entity eagerly.

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.