【问题标题】:Spring Data JPA saveAll not doing batch insertSpring Data JPA saveAll 不进行批量插入
【发布时间】:2020-03-18 23:45:54
【问题描述】:

所以我使用了一个简单的 JpaRepository 并调用了 saveAll() 方法。

hibernate.jdbc.batch_size = 500
hibernate.order_inserts = true
hibernate.generate_statistics = true

运行应用程序后:

   8045055 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    137189246 nanoseconds spent preparing 1158 JDBC statements;
    1417689514 nanoseconds spent executing 1158 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;
    16270990 nanoseconds spent executing 1 flushes (flushing a total of 1158 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)

任何人都可以看到 0 执行 JDBC 批处理的原因吗? 另外,我必须指出我的实体有 @GeneratedValue(strategy = IDENTITY) 主键

【问题讨论】:

标签: java hibernate spring-data-jpa


【解决方案1】:

同时设置hibernate.order_updates = true

org.hibernate.engine.jdbc.batch.internal.BatchingBatch 的记录器更改为 DEBUG 并查看您得到的输出。

【讨论】:

  • 你在哪里设置这个?
【解决方案2】:

为属性名称添加前缀 spring.jpa.properties。它应该是这样的:

spring.jpa.properties.hibernate.jdbc.batch_size = 500

【讨论】:

    【解决方案3】:

    Hibernate 不使用身份标识符生成器执行插入批处理。 更多信息是here

    【讨论】:

    • 在我的情况下,任何 id 生成策略都不会发生 oracle 插入批处理。是的,我已经设置了属性hibernate.jdbc.batch_size: 100
    猜你喜欢
    • 2023-03-23
    • 2018-01-23
    • 2021-03-09
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 2014-11-14
    相关资源
    最近更新 更多