Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-622

Caching ClassMetadata of an joined subclass with id generator sequence with apc and xml mapping

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      On openSolaris and Mac OS X with postgresql 8.4, PHP 5.3, apc 3.1.3p1

      Description

      Apparently apc is having issues when storing an ClassMetadata object with sequenceGeneratorDefinition. When loading the object, apc seems to have lost this only field. I've just tested it with xml mapping.

      Here is a fail test casse :

      SecondClass and ThirdClass inherit from FirstClass

      SQL

      CREATE TABLE first_class
      (
        id serial NOT NULL,
        "type" integer,
        CONSTRAINT first_class_pkey PRIMARY KEY (id)
      );
      
      CREATE TABLE second_class
      (
        id serial NOT NULL,
        other_stuff character varying,
        CONSTRAINT second_class_pkey PRIMARY KEY (id)
      );
      
      CREATE TABLE third_class
      (
        id serial NOT NULL,
        other_stuff character varying,
        CONSTRAINT third_class_pkey PRIMARY KEY (id)
      );
      

      Xml mapping :

      <?xml version="1.0" encoding="UTF-8"?>
      <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
      
        <entity name="FirstClass" table='"first_class"' inheritance-type="JOINED">
          <id name="id" type="integer" column="id">
            <generator strategy="SEQUENCE"/>
            <sequence-generator sequence-name="first_class_id_seq" allocation-size="1" initial-value="1"/>
          </id>
      
          <discriminator-column name="type" type="integer" field-name="type" />
      
          <discriminator-map>
            <discriminator-mapping value="1" class="SecondClass" />
            <discriminator-mapping value="2" class="ThirdClass" />
          </discriminator-map>
        </entity>
      </doctrine-mapping>
      
      <?xml version="1.0" encoding="UTF-8"?>
      <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
      
        <entity name="SecondClass" table="second_class">
          <field name="otherStuff" column="other_stuff" type="string" />
        </entity>
      </doctrine-mapping>
      
      <?xml version="1.0" encoding="UTF-8"?>
      <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
      
        <entity name="ThirdClass" table="second_class">
          <field name="otherStuff" column="other_stuff" type="string" />
        </entity>
      </doctrine-mapping>
      

      Php classes :

      class FirstClass {
      
        private $id;
        private $type;
      }
      
      class SecondClass extends FirstClass {
        private $otherStuff;
      }
      
      class ThirdClass extends FirstClass {
        private $otherStuff;
      }
      

      First scipt to execute so that Doctrine store FirstClass metadata in cache :

      $firstClass = new FirstClass();
      $doctrineEntityManager->persist($firstClass);
      
      $secondClass = new SecondClass();
      $doctrineEntityManager->persist($secondClass);
      

      and then we execute the last script :

      $firstClass = new FirstClass();
      $doctrineEntityManager->persist($firstClass);
      
      
      $thirdClass = new ThirdClass();
      $doctrineEntityManager->persist($thirdClass);
      

      Obviously, Doctrine loads FirstClass Metadata from the cache and fails to create ThirdClass Metadata :

      Catchable fatal error: Argument 1 passed to Doctrine\ORM\Mapping\ClassMetadataInfo::setSequenceGeneratorDefinition() must be an array, null given, called in doctrine/2.0.0-BETA1/Doctrine/ORM/Mapping/ClassMetadataFactory.php on line 269 and defined in doctrine/2.0.0-BETA1/Doctrine/ORM/Mapping/ClassMetadataInfo.php on line 1222
      

        Activity

        Hide
        Paul Fariello added a comment -

        With a little more debug I found that juste doing :

        unserialize(serialize($data));
        

        On _doSave() method from ApcCache object make me lost the sequenceGeneratorDefinition field...

        Any idea ?

        Show
        Paul Fariello added a comment - With a little more debug I found that juste doing : unserialize(serialize($data)); On _doSave() method from ApcCache object make me lost the sequenceGeneratorDefinition field... Any idea ?
        Hide
        Roman S. Borschel added a comment -

        Yes, its a bug in ClassMetadata#__sleep. Will be fixed soon. Thanks for reporting.

        Show
        Roman S. Borschel added a comment - Yes, its a bug in ClassMetadata#__sleep. Will be fixed soon. Thanks for reporting.
        Hide
        Roman S. Borschel added a comment -

        Thanks. This is fixed now.

        Show
        Roman S. Borschel added a comment - Thanks. This is fixed now.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: