我可以在同一实体 Class 中定义实体侦听器吗?
Can I define the Entity Listeners in the Same Entity Class?
例如,下面的代码 运行 会正确吗?
或者我是否必须为每个实体定义一个单独的实体侦听器 class?
@Entity
@EntityListeners(value = Abc.class)
public class Abc{
...
@PreUpdate
public void doPreUpdate(){
//do something
}
...
}
您甚至不需要 @EntityListeners
注释。仅使用 @PreUpdate
注释方法即可正常工作。
来自 @PreUpdate
的 javadoc:
This annotation may be applied to methods of an entity class, a mapped
superclass, or a callback listener class.
例如,下面的代码 运行 会正确吗? 或者我是否必须为每个实体定义一个单独的实体侦听器 class?
@Entity
@EntityListeners(value = Abc.class)
public class Abc{
...
@PreUpdate
public void doPreUpdate(){
//do something
}
...
}
您甚至不需要 @EntityListeners
注释。仅使用 @PreUpdate
注释方法即可正常工作。
来自 @PreUpdate
的 javadoc:
This annotation may be applied to methods of an entity class, a mapped superclass, or a callback listener class.