【问题标题】:Understanding Hibernate Partial Flush behavior了解 Hibernate 部分刷新行为
【发布时间】:2014-12-03 13:01:03
【问题描述】:

在我的 java 应用程序(使用 Hibernate)中,我从 Hibernate Metrics 中看到了以下详细信息

    org.hibernate.engine.internal.StatisticalLoggingSessionEventListener Session Metrics {
46195 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
148413278 nanoseconds spent preparing 1300 JDBC statements;
203780356679 nanoseconds spent executing 1300 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
414686772 nanoseconds spent executing 2 flushes (flushing a total of 1376 entities and 0 collections);
325171056 nanoseconds spent executing 650 partial-flushes (flushing a total of 107052 entities and 107052 collections)

典型的代码流程是使用源表中的数据为一些目标表准备数据:

  • 从多个源表[4到5表]中选择记录,
  • 进行一些处理,为最终目标表 [1-3 表] 准备数据。在处理的任何时候源表实体都没有变化。也没有使用本机查询。
  • 在最终表格中保留记录。

我想获得一些关于寻找什么来确定可能导致部分刷新的指示。

谢谢

【问题讨论】:

    标签: java mysql hibernate


    【解决方案1】:

    你必须在你打算持久化的方法中指明@Transactional注解。

    【讨论】:

      【解决方案2】:

      确保 final[target] 表在每个表中都有外键索引。这将减少创建的间歇性集合的数量,从而减少要刷新的集合的数量。

      根据我的经验,如果最终表格中有连接,它也可以创建更多的部分集合。

      【讨论】:

        猜你喜欢
        • 2011-09-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-14
        • 2021-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多