diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index 9eb83c2b8..01a24f7d4 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -377,7 +377,8 @@ class AnnotationDriver implements Driver // Evaluate @HasLifecycleCallbacks annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) { foreach ($class->getMethods() as $method) { - if ($method->isPublic()) { + // filter for the declaring class only, callbacks from parents will already be registered. + if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) { $annotations = $this->_reader->getMethodAnnotations($method); if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) { diff --git a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php index 031acc941..f02401975 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php @@ -167,6 +167,26 @@ class AnnotationDriverTest extends AbstractMappingDriverTest "superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'."); $usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'); } + + /** + * @group DDC-1034 + */ + public function testInheritanceSkipsParentLifecycleCallbacks() + { + $annotationDriver = $this->_loadDriver(); + + $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\AnnotationChild'); + $em = $this->_getTestEntityManager(); + $em->getConfiguration()->setMetadataDriverImpl($annotationDriver); + $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory->setEntityManager($em); + + $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild'); + $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks); + + $cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent'); + $this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks); + } } /** @@ -208,4 +228,43 @@ class UsingInvalidMappedSuperClass extends InvalidMappedSuperClass class MappedSuperClassInheritence { +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorMap({"parent" = "AnnotationParent", "child" = "AnnotationChild"}) + * @HasLifecycleCallbacks + */ +class AnnotationParent +{ + /** + * @Id @Column(type="integer") @GeneratedValue + */ + private $id; + + /** + * @PostLoad + */ + public function postLoad() + { + + } + + /** + * @PreUpdate + */ + public function preUpdate() + { + + } +} + +/** + * @Entity + * @HasLifecycleCallbacks + */ +class AnnotationChild extends AnnotationParent +{ + } \ No newline at end of file