Spring Boot Appllication. Batch doesn't work in JpaRepository.saveAll method

yazabara

There is spring boot application with configuration:

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}

I use JpaRepository.saveAll method for inserting new data into DB. But I don't see that batching working.

There is logs:

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)
}

Versions:

  1. spring-data-jpa-2.2.6.RELEASE
  2. postgresql-42.2.12
yazabara

Batch doesn't work with GenerationType.IDENTITY

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

Need to use sequence.

Example:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related