原则 2:无法让 LifecycleCallBacks 与单表继承实体一起使用?

发布于 2024-12-03 06:58:52 字数 733 浏览 2 评论 0原文

是否存在不允许这样做的错误?我已将 LifecycleCallBacks 注释和 prepersist 方法放入基类中(也尝试了子类),但无法让 LifecycleCallBacks 工作。任何意见将不胜感激!谢谢!

/**
 * @Entity(repositoryClass="Entity\Repository\EventRepository") 
 * @HasLifecycleCallbacks
 * @Table(name="events")
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="type", type="string")
 * @DiscriminatorMap({"phone" = "PhoneEvent", "meeting" = "MeetingEvent"})
 */
class Event implements \ActivityItem{

    /** @PrePersist */
    public function setComplianceStatus(){...}

}

这不起作用,所以我也尝试过:

/**
 * @Entity @HasLifecycleCallbacks
 */
class PhoneEvent extends Event{

    /** @PrePersist */
    public function setComplianceStatus(){}
}

Is there a bug that doesn't allow this? I've put the LifecycleCallBacks annotation and a prepersist method into the base class (also tried the child classes as well) and can't get LifecycleCallBacks to work. Any input would be greatly appreciated! Thanks!

/**
 * @Entity(repositoryClass="Entity\Repository\EventRepository") 
 * @HasLifecycleCallbacks
 * @Table(name="events")
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="type", type="string")
 * @DiscriminatorMap({"phone" = "PhoneEvent", "meeting" = "MeetingEvent"})
 */
class Event implements \ActivityItem{

    /** @PrePersist */
    public function setComplianceStatus(){...}

}

This didn't work, so I also tried:

/**
 * @Entity @HasLifecycleCallbacks
 */
class PhoneEvent extends Event{

    /** @PrePersist */
    public function setComplianceStatus(){}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百合的盛世恋 2024-12-10 06:58:52

我用你提出的映射进行了尝试,该星座似乎确实存在问题。

当我这样做时它起作用了:

/**
 * ...
 * @Entity
 * @HasLifecycleCallbacks
 */
class Event {
    ...

    /** @PrePersist */
    public abstract function setComplianceStatus();

    ...
}


/**
 * @Entity
 * @HasLifecycleCallbacks
 */
class PhoneEvent extends Event{

    /** @PrePersist */
    public function setComplianceStatus() {
        // implementation goes here
    }
}

因为看起来该方法必须存在于父类中,即使它可以声明为抽象的。奇怪,可能是bug。

I tried it with the mapping you proposed and there really seems to be a problem in that constellation.

It worked when I did:

/**
 * ...
 * @Entity
 * @HasLifecycleCallbacks
 */
class Event {
    ...

    /** @PrePersist */
    public abstract function setComplianceStatus();

    ...
}


/**
 * @Entity
 * @HasLifecycleCallbacks
 */
class PhoneEvent extends Event{

    /** @PrePersist */
    public function setComplianceStatus() {
        // implementation goes here
    }
}

As it seems the method has to be present in the parent class, even though it can be declared as abstract. Strange, might be a bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文