XML中的Doctrine类继承
发布时间:2020-12-16 07:45:16 所属栏目:百科 来源:网络整理
导读:我正在尝试使用Doctrine 2 ORM设置类继承,但是我遇到错误(即使遵循他们的示例).我正在使用Symfony 2沙箱中的控制台.这个简单的例子使用Person和Employee类;员工扩展人员. 我在尝试生成实体时遇到的错误是: [DoctrineORMMappingMappingException]Entity c
我正在尝试使用Doctrine 2 ORM设置类继承,但是我遇到错误(即使遵循他们的示例).我正在使用Symfony 2沙箱中的控制台.这个简单的例子使用Person和Employee类;员工扩展人员.
我在尝试生成实体时遇到的错误是: [DoctrineORMMappingMappingException] Entity class 'Employee' used in the discriminator map of class 'ApplicationMyBundleEntityPerson' 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="ApplicationMyBundleEntityPerson" 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="ApplicationMyBundleEntityEmployee"> <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:SVNSymfonysymfony-sandboxsrcvendordoctrinelibDoctrineORMMappi ngMappingException.php:187 DoctrineORMMappingMappingException::invalidClassInDiscriminatorMap() at C:S VNSymfonysymfony-sandboxsrcvendordoctrinelibDoctrineORMMappingClassMet adataInfo.php:1465 DoctrineORMMappingClassMetadataInfo->setDiscriminatorMap() at C:SVNSymfony symfony-sandboxsrcvendordoctrinelibDoctrineORMMappingDriverXmlDriver.p hp:98 DoctrineORMMappingDriverXmlDriver->loadMetadataForClass() at C:SVNSymfony symfony-sandboxsrcvendordoctrinelibDoctrineORMMappingDriverDriverChain .php:75 DoctrineORMMappingDriverDriverChain->loadMetadataForClass() at C:SVNSymfo nysymfony-sandboxsrcvendordoctrinelibDoctrineORMMappingClassMetadataFac tory.php:280 DoctrineORMMappingClassMetadataFactory->loadMetadata() at C:SVNSymfonysym fony-sandboxsrcvendordoctrinelibDoctrineORMMappingClassMetadataFactory.p hp:178 DoctrineORMMappingClassMetadataFactory->getMetadataFor() at C:SVNSymfonys ymfony-sandboxsrcvendordoctrinelibDoctrineORMMappingClassMetadataFactory .php:125 DoctrineORMMappingClassMetadataFactory->getAllMetadata() at C:SVNSymfonys ymfony-sandboxsrcvendorsymfonysrcSymfonyBundleDoctrineBundleCommandDoct rineCommand.php:143 SymfonyBundleDoctrineBundleCommandDoctrineCommand->getBundleMetadatas() at C:SVNSymfonysymfony-sandboxsrcvendorsymfonysrcSymfonyBundleDoctrineBun dleCommandGenerateEntitiesDoctrineCommand.php:77 SymfonyBundleDoctrineBundleCommandGenerateEntitiesDoctrineCommand->execute( ) at C:SVNSymfonysymfony-sandboxsrcvendorsymfonysrcSymfonyComponentCon soleCommandCommand.php:150 SymfonyComponentConsoleCommandCommand->run() at C:SVNSymfonysymfony-sand boxsrcvendorsymfonysrcSymfonyComponentConsoleApplication.php:184 SymfonyComponentConsoleApplication->doRun() at C:SVNSymfonysymfony-sandbo xsrcvendorsymfonysrcSymfonyBundleFrameworkBundleConsoleApplication.php: 74 SymfonyBundleFrameworkBundleConsoleApplication->doRun() at C:SVNSymfonys ymfony-sandboxsrcvendorsymfonysrcSymfonyComponentConsoleApplication.php: 113 SymfonyComponentConsoleApplication->run() at C:SVNSymfonysymfony-sandbox appconsole:11
我得到了同样的错误.
我想出了该怎么做: 在您的示例中,您必须已生成“员工”实体. >在Person中删除继承并在Employee中添加id 为我工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |