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

Closed
doctrinebot opened this Issue Oct 8, 2010 · 2 comments

2 participants

@doctrinebot

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
@doctrinebot

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

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment