我正在阅读有关实体回调和监听器的内容,我得到了一个在我脑海中不太清楚的解释:
When an event is raised, the listeners are executed in this order:
1 @EntityListeners for a given entity or superclass in the array order
2 Entity listeners for the superclasses (highest first)
3 Entity Listeners for the entity
4 Callbacks of the superclasses (highest first)
5 Callbacks of the entity
以上文字摘自here它出现在网络上的不同位置,但形式几乎相同。
1和3有什么区别? 3 是否意味着“全局”xml 文件中定义的监听器?
最佳答案
1 @EntityListener for a given entity
表示Entity本身的@PostLoad、@PrePersist等回调方法
3 Entity Listeners for the entity
表示实体类上的@EntityListener注解。
如果您定义“全局”orm.xml 并为其中的实体设置实体监听器,那么它将覆盖实体本身的注释。 https://docs.jboss.org/hibernate/stable/annotations/reference/en/html/xml-overriding.html
关于java - 实体监听器调用顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23824638/