【问题标题】:how to do batch insert/update with Springboot data JPA and Mysql如何使用 Spring Boot 数据 JPA 和 Mysql 进行批量插入/更新
【发布时间】:2020-07-17 05:23:25
【问题描述】:

我正在尝试通过 Mysql 使用 SpringBoot Data Jpa 实现批量插入/更新记录, 这是我的 yml 配置:

spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.jdbc.batch_size=500
spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true
spring.jpa.properties.hibernate.generate_statistics=true

我在这里使用 mysql 自增列作为主键

public class Customer implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
}

我在 Google 上搜索到批处理操作不适用于 GenerationType.IDENTITY, 但我也注意到 mysql 不支持 GenerationType.SEQUENCE 那么我怎么能用jpa的saveAll(data)方法和mysql DB完成浴插入/更新

谢谢

【问题讨论】:

    标签: mysql spring-boot spring-data-jpa


    【解决方案1】:

    我在 Google 上搜索到批处理操作不适用于 GenerationType.IDENTITY,但我也注意到 mysql 不支持 GenerationType.SEQUENCE

    在应用程序中设置 id。例如使用UUID

    【讨论】:

    • 出于某种原因,我更喜欢使用 db auto increment primary key(GenerationType.IDENTITY) 而不是 uuid 。有什么解决方法吗?
    猜你喜欢
    • 2014-11-14
    • 2019-05-02
    • 2018-05-17
    • 2021-08-13
    • 1970-01-01
    • 2021-03-15
    • 2018-11-14
    • 2018-07-08
    • 2019-02-09
    相关资源
    最近更新 更多