sql - JPA batch_size 属性不适用于本机查询
问题描述
我正在尝试使用本机查询进行批量插入。
@Repository
public interface Repository extends CrudRepository<Entity, Integer> {
@Modifying
@Query(value = "INSERT INTO table_name(value) VALUES (:value)", nativeQuery = true)
void insert(@Param("value") String value);
}
我已将 batch_size 属性添加到 application.properties 文件
spring.jpa.properties.hibernate.jdbc.batch_size = 50
但是在日志中,我看到每个插入都是单独处理的。是否可以将批处理应用于本机查询?
解决方案
如果实体使用GenerationType.IDENTITY
标识符生成器,休眠将静默禁用批量插入/更新。
详情请查看以下链接: https ://www.baeldung.com/jpa-hibernate-batch-insert-update#id-generation-strategy
推荐阅读
- python - 如何将数据框拆分为 n 个大小相等的部分?(观察次数)
- python - 将数据导出到scrapy中的单独csv文件
- graphql - graphql 突变不返回嵌套字段
- arduino - 将 ESP32 与 HC-05 BT 模块配对
- javascript - $set 在 mongo 聚合查询中不替换 $unwind 和 $match 之后的值
- c++ - 我想了解为什么在这个例子中使用引用函数?或者 C++ 函数中引用的重要性?
- python - 如何在自定义对象创建类方法中创建实例
- python - 检查嵌套列表中是否没有
- jquery - 无法解析 AJAX 响应中的嵌套 JSON
- node.js - createHmac 从 Buffer 中给出两种不同的输出