Spring Boot 应用程序。批处理在 JpaRepository.saveAll 方法中不起作用

矢座原

有带有配置的spring boot应用程序:

spring:
  jpa:
    show-sql: true
    properties:
      hibernate:
        jdbc:
          batch_size: 20
        order_inserts: true
        order_updates: true
        generate_statistics: true
        format_sql: true
        dialect: org.hibernate.dialect.PostgreSQL10Dialect
        default_schema: ${SCHEMA}

我使用 JpaRepository.saveAll 方法将新数据插入数据库。但我没有看到批处理工作。

有日志:

Session Metrics {
    1501300 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    13234500 nanoseconds spent preparing 1013 JDBC statements;
    1636949500 nanoseconds spent executing 1013 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;
    12971600 nanoseconds spent executing 1 flushes (flushing a total of 1012 entities and 0 collections);
    4901200 nanoseconds spent executing 2 partial-flushes (flushing a total of 4 entities and 4 collections)
}

版本:

  1. spring-data-jpa-2.2.6.RELEASE
  2. postgresql-42.2.12
矢座原

批处理不适用于 GenerationType.IDENTITY

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

需要使用顺序。

例子:

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "row_generator")
@SequenceGenerator(name = "row_generator", sequenceName = "db_generator", allocationSize = 1)
private Long id;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot JpaRepository接口

如何在Spring Boot应用程序的@Transactional方法中使用纯Hibernate保证原子批处理插入

无法在Junit测试中自动装配JpaRepository-Spring Boot应用程序

ServiceLoader在打包的Spring Boot应用程序中不起作用

在JpaRepository中刷新saveAll

JPARepository接口是否涵盖Spring Boot中DAO接口的职责?

Spring Boot中的异常处理程序不起作用?

在Spring Boot应用程序中配置cors。Bean CorsConfigurationSource不起作用

为什么AOP在我的Spring Boot应用程序中不起作用?

onetoone映射在我的Spring Boot Rest应用程序和json mysql中不起作用

如何在Spring Boot中摆脱JpaRepository接口

注销在Spring Boot应用程序中不起作用(不支持POST方法)

带有JSTL的JSP在Spring Boot应用程序中的tomcat 8上不起作用

带有@Scheduled批注的方法在Spring Boot应用程序中不起作用

MapStruct实现在Spring Boot Web应用程序中不起作用

非Web非批处理Spring Boot应用程序的应用程序逻辑应放在哪里?

JpaRepository接口中的Spring Boot覆盖保存方法

CommonsRequestLoggingFilter在Spring Boot应用程序中不起作用

弹性搜索在Spring Boot应用程序中不起作用

简单的Spring Boot应用程序不起作用

控制器到某些功能的映射在已部署的Spring Boot应用程序中不起作用

Spring批处理应用程序中的Spring JdbcCursorItemReader

RabbitTemplate 没有结束 spring boot + spring 批处理作业应用程序

Spring boot - Jpa - SaveAll(Entity <S>) 数据库中缺少实体

Spring-boot 应用程序:端口映射在 docker 中不起作用

deleteByIdAndXXX 与 Spring Boot JpaRepository

Spring Boot JpaRepository 未导入

为什么@PostConstruct 在 Spring Boot 应用程序中不起作用?

Spring Boot 2.6.5 中的 JpaRepository 抛出异常