Inheriting the Doctrine Class in XML

I am trying to set up class inheritance using ORM Doctrine 2, but I am getting errors (even when executing their examples). I use the console from the Symfony 2 sandbox. The simple example uses the Person and Employee classes; Employee Expands Face .

Error trying to generate entities:

 [Doctrine \ ORM \ Mapping \ MappingException]

 Entity class 'Employee' used in the discriminator map of class 'Application \ MyBundle \ Entity \ Person' does not exist.

Presented XML below:

Person

<?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Application\MyBundle\Entity\Person" inheritance-type="SINGLE_TABLE"> <change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy> <id name="id" type="integer" column="id"> <generator strategy="AUTO"/> </id> <discriminator-column name="discr" type="string" /> <discriminator-map> <discriminator-mapping value="employee" class="Employee" /> </discriminator-map> <lifecycle-callbacks/> </entity> </doctrine-mapping> 

Employee

 <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Application\MyBundle\Entity\Employee"> <change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy> <id name="id" type="integer" column="id"> <generator strategy="AUTO"/> </id> <lifecycle-callbacks/> </entity> </doctrine-mapping> 

It seems that many people use XML to customize their Doctrine entities (most examples use PHP annotations), but this seems to me the most logical, so I would like to know how to do it properly. Has anyone else had this problem or was aware of a solution?

The full exception trace is as follows:

 Exception trace:
  () at C: \ SVN \ Symfony \ symfony-sandbox \ src \ vendor \ doctrine \ lib \ Doctrine \ ORM \ Mappi
 ng \ MappingException.php: 187
  Doctrine \ ORM \ Mapping \ MappingException :: invalidClassInDiscriminatorMap () at C: \ S
 VN \ Symfony \ symfony-sandbox \ src \ vendor \ doctrine \ lib \ Doctrine \ ORM \ Mapping \ ClassMet
 adataInfo.php: 1465
  Doctrine \ ORM \ Mapping \ ClassMetadataInfo-> setDiscriminatorMap () at C: \ SVN \ Symfony
 \ symfony-sandbox \ src \ vendor \ doctrine \ lib \ Doctrine \ ORM \ Mapping \ Driver \ XmlDriver.p
 hp: 98
  Doctrine \ ORM \ Mapping \ Driver \ XmlDriver-> loadMetadataForClass () at C: \ SVN \ Symfony
 \ symfony-sandbox \ src \ vendor \ doctrine \ lib \ Doctrine \ ORM \ Mapping \ Driver \ DriverChain
 .php: 75
  Doctrine \ ORM \ Mapping \ Driver \ DriverChain-> loadMetadataForClass () at C: \ SVN \ Symfo
 ny \ symfony-sandbox \ src \ vendor \ doctrine \ lib \ Doctrine \ ORM \ Mapping \ ClassMetadataFac
 tory.php: 280
  Doctrine \ ORM \ Mapping \ ClassMetadataFactory-> loadMetadata () at C: \ SVN \ Symfony \ sym
 fony-sandbox \ src \ vendor \ doctrine \ lib \ Doctrine \ ORM \ Mapping \ ClassMetadataFactory.p
 hp: 178
  Doctrine \ ORM \ Mapping \ ClassMetadataFactory-> getMetadataFor () at C: \ SVN \ Symfony \ s
 ymfony-sandbox \ src \ vendor \ doctrine \ lib \ Doctrine \ ORM \ Mapping \ ClassMetadataFactory
 .php: 125
  Doctrine \ ORM \ Mapping \ ClassMetadataFactory-> getAllMetadata () at C: \ SVN \ Symfony \ s
 ymfony-sandbox \ src \ vendor \ symfony \ src \ Symfony \ Bundle \ DoctrineBundle \ Command \ Doct
 rineCommand.php: 143
  Symfony \ Bundle \ DoctrineBundle \ Command \ DoctrineCommand-> getBundleMetadatas () at
 C: \ SVN \ Symfony \ symfony-sandbox \ src \ vendor \ symfony \ src \ Symfony \ Bundle \ DoctrineBun
 dle \ Command \ GenerateEntitiesDoctrineCommand.php: 77
  Symfony \ Bundle \ DoctrineBundle \ Command \ GenerateEntitiesDoctrineCommand-> execute (
 ) at C: \ SVN \ Symfony \ symfony-sandbox \ src \ vendor \ symfony \ src \ Symfony \ Component \ Con
 sole \ Command \ Command.php: 150
  Symfony \ Component \ Console \ Command \ Command-> run () at C: \ SVN \ Symfony \ symfony-sand
 box \ src \ vendor \ symfony \ src \ Symfony \ Component \ Console \ Application.php: 184
  Symfony \ Component \ Console \ Application-> doRun () at C: \ SVN \ Symfony \ symfony-sandbo
 x \ src \ vendor \ symfony \ src \ Symfony \ Bundle \ FrameworkBundle \ Console \ Application.php:
 74
  Symfony \ Bundle \ FrameworkBundle \ Console \ Application-> doRun () at C: \ SVN \ Symfony \ s
 ymfony-sandbox \ src \ vendor \ symfony \ src \ Symfony \ Component \ Console \ Application.php:
 113
  Symfony \ Component \ Console \ Application-> run () at C: \ SVN \ Symfony \ symfony-sandbox \
 app \ console: 11
+7
xml orm symfony doctrine2
source share
3 answers

I have the same error.

I figured out what to do:

In your example, you should have an already formed Employee object.

  • remove inheritance in Person and add identifier in Employee
  • Doctrine: Generating: Objects
  • define xmls as they were at the beginning
  • Doctrine: Generating: Objects

Worked for me.

+5
source share

When defining a discriminator, you should probably use the fully qualified name of the class (with namespaces).

how

 <discriminator-map> <discriminator-mapping value="employee" class="Application\MyBundle\Entity\Employee" /> </discriminator-map> 
+2
source share

Class names in the discriminator card need not be fully qualified if the classes are contained in the same namespace as the class on which the discriminator card is used.

6.2. Inheritance of individual tables

0
source share

All Articles