【发布时间】:2021-10-02 13:47:23
【问题描述】:
应用程序属性
spring.datasource.url=jdbc:as400://localhost/
spring.jpa.properties.hibernate.jdbc.batch_size = 30
spring.jpa.properties.hibernate.order_updates = true
spring.jpa.properties.hibernate.batch_versioned_data = true
实体 -
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "entity")
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", nullable = false);
@ManyToOne
@JoinColumn(name = "HDR_ID", referencedColumnName = "HDR_ID")
@JsonIgnore
private Header header;
@ManyToOne
@JoinColumn(name = "STS_ID", referencedColumnName = "STS_ID")
private Status status;
}
服务-
this.myRepository.saveAll(MyEntitylist);
Gradle -
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
implementation 'org.springframework.boot:spring-boot-starter-web'
我正在使用 Spring Boot 2.3.5.RELEASE。 我正在尝试使用休眠批处理更新批量记录,但它似乎不起作用。我没有收到任何错误,记录在数据库中更新没有任何问题,但没有性能改进。实际上,无论有没有 Hibernate 批处理,我都找不到任何区别。我检查了日志,他们的查询记录了每条记录,例如,如果我尝试保存 1000 条记录,那么日志中将有 1000 个更新查询。
我预计批处理后的更新查询会减少,具体取决于批处理大小,并且与没有批处理查询相比,它应该花费更少的时间。
我的代码中是否存在任何配置问题? jdbc:as400 是否有类似 reWriteBatchedInserts 的选项来显示多行插入查询?
【问题讨论】:
-
您的帖子并没有真正说明您要解决的问题是什么。您是否收到错误消息?您的 MyEntity 类中似乎缺少 Id 成员。
-
嗨@crig,我在帖子中添加了更多细节。我正在尝试使用批处理来提高性能,但它似乎不起作用,而且我也没有收到任何错误,
标签: java spring-boot hibernate jpa