【问题标题】:What does Hibernate PostInsertEventListener.requiresPostCommitHanding do?Hibernate PostInsertEventListener.requiresPostCommitHanding 做什么?
【发布时间】:2021-06-30 06:55:22
【问题描述】:

在文档 [1] 中说:

此侦听器是否要求注册后事务挂钩?

这是否意味着,如果我们返回 false 和之后如果我们返回 true,监听器将在事务提交之前运行?

[1]https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/event/spi/PostInsertEventListener.html

【问题讨论】:

    标签: java hibernate


    【解决方案1】:

    看来,当PostInsertEventListener 注册为EventType.POST_INSERT 时,根本不会调用该方法,并且侦听器总是在提交事务之前执行。

    但是,如果侦听器注册为EventType.POST_COMMIT_INSERT,则实际调用该方法,如果它返回true,则将在提交事务后调用侦听器。如果它返回 false,则侦听器将不会被调用。

    此外,如果侦听器的类型为PostInsertEventListener,则无论事务是否成功,都将调用onPostInsert 方法。如果侦听器的类型为PostCommitInsertEventListener,则只有成功的事务才会调用onPostInsert 方法。否则,将调用onPostInsertCommitFailed 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-31
      • 2017-09-02
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      相关资源
      最近更新 更多