我正在尝试使用 Doctrine 2 ORM 设置类继承,但遇到错误(即使遵循他们的示例)。我正在使用 Symfony 2 沙箱中的控制台。这个简单的例子使用了Person和Employee类;一个Employee扩展了Person。
我在尝试生成实体时遇到的错误是:
[学说\ORM\映射\映射异常] 'Application\MyBundle\Entity\Person' 类的鉴别器映射中使用的实体类 'Employee' 不存在。
正在尝试的 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 注释),但对我来说这似乎是最合乎逻辑的,所以我想知道如何正确地做到这一点。有没有其他人遇到过这个问题,或者知道解决方案?
完整的异常跟踪如下:
异常跟踪: () 在 C:\SVN\Symfony\symfony-sandbox\src\vendor\doctrine\lib\Doctrine\ORM\Mappi ng\MappingException.php:187 Doctrine\ORM\Mapping\MappingException::invalidClassInDiscriminatorMap() 在 C:\S VN\Symfony\symfony-sandbox\src\vendor\doctrine\lib\Doctrine\ORM\Mapping\ClassMet adataInfo.php:1465 Doctrine\ORM\Mapping\ClassMetadataInfo->setDiscriminatorMap() 在 C:\SVN\Symfony \symfony-sandbox\src\vendor\doctrine\lib\Doctrine\ORM\Mapping\Driver\XmlDriver.p 马力:98 Doctrine\ORM\Mapping\Driver\XmlDriver->loadMetadataForClass() 在 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 马力:178 Doctrine\ORM\Mapping\ClassMetadataFactory->getMetadataFor() at C:\SVN\Symfony\s ymfony 沙盒\src\vendor\doctrine\lib\Doctrine\ORM\Mapping\ClassMetadataFactory .php:125 Doctrine\ORM\Mapping\ClassMetadataFactory->getAllMetadata() 在 C:\SVN\Symfony\s ymfony 沙盒\src\vendor\symfony\src\Symfony\Bundle\DoctrineBundle\Command\Doct rineCommand.php:143 Symfony\Bundle\DoctrineBundle\Command\DoctrineCommand->getBundleMetadatas() 在 C:\SVN\Symfony\symfony-sandbox\src\vendor\symfony\src\Symfony\Bundle\DoctrineBun dle\Command\GenerateEntitiesDoctrineCommand.php:77 Symfony\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute( ) 在 C:\SVN\Symfony\symfony-sandbox\src\vendor\symfony\src\Symfony\Component\Con 唯一\Command\Command.php:150 Symfony\Component\Console\Command\Command->run() at C:\SVN\Symfony\symfony-sand 框\src\vendor\symfony\src\Symfony\Component\Console\Application.php:184 Symfony\Component\Console\Application->doRun() 在 C:\SVN\Symfony\symfony-sandbo x\src\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php: 74 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() 在 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\ 应用\控制台:11