java - Spring Boot - 批量更新单独插入记录而不是批量插入
问题描述
我正在尝试进行批量插入(spring boot,jpa,hibernate),当我查看生成的统计信息时,意识到它仍在将它们一个接一个地插入,而不是作为一个批处理。下面是配置和使用 JpaRepository 的 saveAll(collection) 方法。我唯一的预感是,我使用的是分配的主键而不是生成的主键,不确定这是否是原因。
我该如何解决这个问题?
特性
spring.jpa.properties.hibernate.jdbc.batch_size=10
spring.jpa.properties.hibernate.order_inserts = true
spring.jpa.properties.hibernate.order_updates = true
spring.jpa.properties.hibernate.batch_versioned_data=true
spring.jpa.properties.hibernate.generate_statistics=true
@Id
@Column(name = "SKU")
private String sku;
统计数据:
43972157 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
128270518 nanoseconds spent preparing 10 JDBC statements;
1320687164 nanoseconds spent executing 8 JDBC statements;
126666002 nanoseconds spent executing 2 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
152061315 nanoseconds spent executing 2 flushes (flushing a total of 16 entities and 0 collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
解决方案
chunk
调整步长和hibernate.jdbc.batch_size
休眠状态会很好。
推荐阅读
- android - 如何用 Fragment Scenario 测试 Fragment?
- elasticsearch - 在elasticsearch中搜索嵌套文档中除以or子句的多个字段
- sql - 如何查看 db2 服务器中最近更新的表?
- laravel - Laravel 事件触发,Echo 监听但不经过函数
- javascript - styled-component 的类型与“strict: true”不匹配
- rest - 谷歌云文本到语音 REST API 身份验证
- java - 如何在 java 中检查集合 mongo db?
- mule - 由于 JDK 问题,无法打开 Anypoint 工作室
- javascript - 如何在事件发生 jQuery 的 div 之外获取数据属性?
- android - Andorid Webview 如何将数据发布到 application/x-www-form-urlencoded