Skip to content

Loading…

DDC-622: Caching ClassMetadata of an joined subclass with id generator sequence with apc and xml mapping #5132

Closed
doctrinebot opened this Issue · 4 comments

1 participant

@doctrinebot

Jira issue originally created by user needle:

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

Comment created by needle:

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 ?

@doctrinebot

Comment created by romanb:

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

@doctrinebot

Comment created by romanb:

Thanks. This is fixed now.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-BETA2 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.