Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

PrePersist in MappedSuperclass fires multiple times #427

Closed
Bilge opened this Issue Oct 10, 2012 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

Bilge commented Oct 10, 2012

A PrePersist function in a MappedSuperclass that is not overridden in the derived class fires three times instead of just once. If the subclass does override it, and annotates the function, it is called twice instead of just once. If the subclass does override it but does not annotate it then it is called just once as expected.

/** @MappedSuperclass */
abstract class Super {
    /** @PrePersist */
    public function prePersist() {
        var_dump('Super');
    }
}

class Sub extends Super { }

$dm->persist(new Sub);
$dm->flush(); //Super::prePersist() called 3 times.

#-OR-

class Sub extends Super {
    /** @PrePersist */
    public function prePersist() {
        var_dump('Sub');
    }
}

$dm->persist(new Sub);
$dm->flush(); //Sub::prePersist() called 2 times.

#-OR-

class Sub extends Super {
    public function prePersist() {
        var_dump('Sub');
    }
}

$dm->persist(new Sub);
$dm->flush(); //Sub::prePersist() called once.
Owner

jmikola commented Jan 9, 2014

HasLifecycleCallbacksTest in #428 will test for this, as we cover all permutations of super/sub classes with @HasLifecycleCallback annotations and overridden methods (8 total). The proper behavior will be for no method to be invoked more than once. That is currently happening in the PR for all but one case (to be fixed) where both the super and sub are annotated and the sub-class overrides the method, too.

@jmikola jmikola closed this in 59a67f3 Jan 9, 2014

Owner

jmikola commented Jan 9, 2014

#428 is merged, so this should be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment