gpt4 book ai didi

java - JPA 2 : How many methods are allowed in one entity with @Prepersist annotation?

转载 作者:行者123 更新时间:2023-12-02 00:01:35 24 4
gpt4 key购买 nike

在 JPA 2 中,可以使用 @PrePersist 这样的注释来声明多少个方法以及这些方法的执行顺序?有时我们也会为监听器创建不同的类,并使用@EntityListener注解将该类应用到实体上,并且我们还在实体中声明方法,那么这些方法的执行顺序是什么?

最佳答案

关于调用顺序,JPA 2 规范第 3.5 节规定:

If multiple entity listeners are defined, the order in which they are invoked is determined by the order in which they are specified in the EntityListeners annotation. The XML descriptor may be used as an alternative to specify the invocation order of entity listeners or to override the order specified in metadata annotations.

关于是否对同一生命周期事件使用多种方法,JPA 2 规范在第 3.5 节中指出:

A single class must not have more than one lifecycle callback method for the same lifecycle event. The same method may be used for multiple callback events.

关于java - JPA 2 : How many methods are allowed in one entity with @Prepersist annotation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14722970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com