diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index cd7a6da68..506f99763 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -325,7 +325,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface if (!$class->discriminatorColumn) { throw MappingException::missingDiscriminatorColumn($class->name); } - } else if ($class->isMappedSuperclass && (count($class->discriminatorMap) || $class->discriminatorColumn)) { + } else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) { + // second condition is necessary for mapped superclasses in the middle of an inheritance hierachy throw MappingException::noInheritanceOnMappedSuperClass($class->name); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index be8a9bc43..e946a2628 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -184,6 +184,21 @@ class AnnotationDriverTest extends AbstractMappingDriverTest $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent'); $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks); } + + /** + * @group DDC-1156 + */ + public function testMappedSuperclassInMiddleOfInheritanceHierachy() + { + $annotationDriver = $this->_loadDriver(); + + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory->setEntityManager($em); + + $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\ChildEntity'); + } } /** @@ -264,4 +279,35 @@ class AnnotationParent class AnnotationChild extends AnnotationParent { +} + +/** + * @Entity + * @InheritanceType("SINGLE_TABLE") + * @DiscriminatorMap({"s"="SuperEntity", "c"="ChildEntity"}) + */ +class SuperEntity +{ + /** @Id @Column(type="string") */ + private $id; +} + +/** + * @MappedSuperclass + */ +class MiddleMappedSuperclass extends SuperEntity +{ + /** @Column(type="string") */ + private $name; +} + +/** + * @Entity + */ +class ChildEntity extends MiddleMappedSuperclass +{ + /** + * @Column(type="string") + */ + private $text; } \ No newline at end of file