我正在尝试使用Doctrine 2 ORM设置类继承,但是我遇到错误(即使遵循他们的示例).我正在使用Symfony 2沙箱中的控制台.这个简单的例子使用Person和Employee类;员工扩展人员.
原文链接:https://www.f2er.com/xml/292378.html[Doctrine\ORM\Mapping\MappingException] Entity class 'Employee' used in the discriminator map of class 'Application\MyBundle\Entity\Person' does not exist.
正在尝试的XML如下:
人
<?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>
雇员
<?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>
似乎很多人不使用XML来配置他们的Doctrine实体(大多数示例都使用PHP注释),但它似乎对我来说最合乎逻辑,所以我想知道如何正确地执行它.有没有其他人有这个问题,或知道解决方案?
完整的异常跟踪如下:
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