首页 > 解决方案 > @Prepersist/@PreUpdate 与 Eclipselink 中的 @Embaddable 未触发

问题描述

从 EclipseLink 文档中它说: Annotation Type PrePersist 和 PreUpdate 为相应的生命周期事件指定回调方法。此注解可以应用于实体类、映射超类或回调侦听器类的方法。

这是否意味着@PrePersist 和@PreUpdate 注释应用于使用@Embeddable 注释注释的类的方法不会被触发?这是我的配置,其中不执行事件 PrePersist 和 PreUpdate。

MyType.clss :

@Entity
@Table(name = "MY_TYPES")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name ="DTYPE",
                 discriminatorType = DiscriminatorType.INTEGER,
                 columnDefinition = "SMALLINT")
@DiscriminatorValue("0")
public class MyType implements Serializable {
    ...
    ...
}

MySpecialType.class :

@Entity
@Table(name = "MY_SPECIAL_TYPES")
@DiscriminatorValue("3")
public class MySpecialType extends MyType implements Serializable {
    ....
    @Valid
    @Embedded
    MyEmbeddable myEmbeddable = new MyEmbeddable();
    ....
}

MyEmbeddable.class :

@Embeddable
public class MyEmbeddable {
    ...
    @PreUpdate
    @PrePersist
    public void doSomething() {
        ...
    }
    ...
}

任何帮助将不胜感激。先感谢您。

标签: eclipselinkweblogic12cjava-ee-7

解决方案


推荐阅读