Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-834

EntityManager::getReference may return proxy for parent class when using class table inheritance

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.0-RC1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      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
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

        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.
        
        Show
        Benjamin Eberlei added a comment - 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.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Patrick Schwisow
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: