yaz*_*ara 1 postgresql spring hibernate jpa spring-data-jpa
有一个带有配置的 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}
Run Code Online (Sandbox Code Playgroud)
我使用 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)
}
Run Code Online (Sandbox Code Playgroud)
版本:
批处理不适用于 GenerationType.IDENTITY
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Run Code Online (Sandbox Code Playgroud)
需要使用顺序。
例子:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "row_generator")
@SequenceGenerator(name = "row_generator", sequenceName = "db_generator", allocationSize = 1)
private Long id;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2906 次 |
| 最近记录: |