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

Closed
opened 2026-01-22 12:59:26 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 8, 2010).

Originally assigned to: @beberlei on GitHub.

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.

Classes:

/****
 * @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
Originally created by @doctrinebot on GitHub (Oct 8, 2010). Originally assigned to: @beberlei on GitHub. 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. Classes: ``` /**** * @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 ```
admin added the Bug label 2026-01-22 12:59:26 +01:00
admin closed this issue 2026-01-22 12:59:28 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 11, 2010):

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.
@doctrinebot commented on GitHub (Oct 11, 2010): 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. ```
Author
Owner

@doctrinebot commented on GitHub (Oct 11, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Oct 11, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1031