Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-248

Exception is thrown during deserialization of the class 'ClassMetadata' if it contains child type

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP 5.3.1 Win32 (XP SP3), pdo_mysql, AnnotationDriver used

      Description

      I have a class hierarchy:
      resource (id, type, name)

      ---> module ()
      ---> controller (ref to module)
      ---> action (ref to controller)
      It is mapped with inheritamce type = "JOINED"
      During the class ClassMetadata deserialization exception belows is thrown:

      ReflectionException: Property id does not exist in E:\Projects\portal\library\Doctrine\ORM\Mapping\ClassMetadata.php on line 362

      Call Stack:
      0.0003 334120 1.

      {main}

      () E:\Projects\DoctrineTest\index.php:0
      0.0291 2124544 2. Doctrine\ORM\EntityManager->find() E:\Projects\DoctrineTest\index.php:24
      0.0291 2124544 3. Doctrine\ORM\EntityManager->getRepository() E:\Projects\portal\library\Doctrine\ORM\EntityManager.php:308
      0.0291 2124544 4. Doctrine\ORM\EntityManager->getClassMetadata() E:\Projects\portal\library\Doctrine\ORM\EntityManager.php:489
      0.0291 2124544 5. Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() E:\Projects\portal\library\Doctrine\ORM\EntityManager.php:220
      0.0291 2124608 6. Doctrine\Common\Cache\AbstractCache->fetch() E:\Projects\portal\library\Doctrine\ORM\Mapping\ClassMetadataFactory.php:133
      0.0292 2124608 7. CacheDriver->_doFetch() E:\Projects\portal\library\Doctrine\Common\Cache\AbstractCache.php:89
      0.0292 2124608 8. CacheDriver->init() E:\Projects\DoctrineTest\CacheDriver.php:61
      0.0293 2127872 9. unserialize() E:\Projects\DoctrineTest\CacheDriver.php:49
      0.0336 2609432 10. Doctrine\ORM\Mapping\ClassMetadata->__wakeup() E:\Projects\portal\library\Doctrine\ORM\Mapping\ClassMetadata.php:0
      0.0340 2633128 11. ReflectionClass->getProperty() E:\Projects\portal\library\Doctrine\ORM\Mapping\ClassMetadata.php:362
      I have attached file with sample code.. I hope it will be helpful

        Activity

        Hide
        Valery Dubrava added a comment -

        I have found workaround:
        1. add to returned by the __sleep method array 'reflClass' and 'reflFields' fields.
        2. write code for recreating the ReflectionClass and ReflectionPropery objects (I think this is a PHP error, Reflection* classes is restored in wrong state). It looks like code below:

         
                $this->reflClass = new \ReflectionClass($this->reflClass->name);
                foreach ($this->reflFields as $field => $reflField) {
                    $this->reflFields[$field] = new \ReflectionProperty($reflField->class, $reflField->name);
                    $this->reflFields[$field]->setAccessible(true);
                }
        
        Show
        Valery Dubrava added a comment - I have found workaround: 1. add to returned by the __sleep method array 'reflClass' and 'reflFields' fields. 2. write code for recreating the ReflectionClass and ReflectionPropery objects (I think this is a PHP error, Reflection* classes is restored in wrong state). It looks like code below: $this->reflClass = new \ReflectionClass($this->reflClass->name); foreach ($this->reflFields as $field => $reflField) { $this->reflFields[$field] = new \ReflectionProperty($reflField->class, $reflField->name); $this->reflFields[$field]->setAccessible(true); }
        Hide
        Valery Dubrava added a comment -

        Sorry, but my workaround doesn't work =(

        Show
        Valery Dubrava added a comment - Sorry, but my workaround doesn't work =(
        Hide
        William Bailey added a comment -

        The issue seems to be that ReflectionClass::getProperty() will only return properties that are defined directly by the class. The attached patch seems to resolve the issue for me.

        Show
        William Bailey added a comment - The issue seems to be that ReflectionClass::getProperty() will only return properties that are defined directly by the class. The attached patch seems to resolve the issue for me.
        Hide
        Roman S. Borschel added a comment -

        Thanks for the patch but I think there is a better (faster) way to resolve this as we know when a field stems from a superclass and the name of that class.

        I will commit a patch soon.

        Show
        Roman S. Borschel added a comment - Thanks for the patch but I think there is a better (faster) way to resolve this as we know when a field stems from a superclass and the name of that class. I will commit a patch soon.
        Hide
        Roman S. Borschel added a comment -

        Should be fixed now.

        Show
        Roman S. Borschel added a comment - Should be fixed now.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Valery Dubrava
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: