In Doctrine2 is it possible to invoke lifecycle callbacks in a base class, which all entities inherit from.
在Doctrine2中,可以在基类中调用生命周期回调,所有实体都从该基类继承。
Something like this http://pastie.org/2650901
这样的东西http://pastie.org/2650901
The problem is that validationCheck()
method doesn't get invoked when I persist or update an entity.
问题是当我持久化或更新实体时,不会调用validationCheck()方法。
Also, I tried making the base class @MappedSuperclass
, but then it breaks all further inheritance, and that is not an option.
此外,我尝试创建基类@MappedSuperclass,但它打破了所有进一步的继承,这不是一个选项。
1 个解决方案
#1
4
Got it working, my mistake.
Here is the solution, if anyone else stumbles on the same issue.
搞定了,我的错误。如果其他人在同一问题上遇到困难,这就是解决方案。
Base class has to have a @MappedSuperclass
and @HasLifecycleCallbacks
notation.
基类必须有@MappedSuperclass和@HasLifecycleCallbacks表示法。
Entity class, if uses further inheritance, has to be abstract
.
如果使用进一步的继承,实体类必须是抽象的。
#1
4
Got it working, my mistake.
Here is the solution, if anyone else stumbles on the same issue.
搞定了,我的错误。如果其他人在同一问题上遇到困难,这就是解决方案。
Base class has to have a @MappedSuperclass
and @HasLifecycleCallbacks
notation.
基类必须有@MappedSuperclass和@HasLifecycleCallbacks表示法。
Entity class, if uses further inheritance, has to be abstract
.
如果使用进一步的继承,实体类必须是抽象的。