JPA batch_size 属性 不适用于本机查询
JPA batch_size property does not work for native query
我正在尝试使用本机查询进行批量插入。
@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
标识符生成器,hibernate 将静默禁用批处理 inserts/updates。
详情请见以下link:
https://www.baeldung.com/jpa-hibernate-batch-insert-update#id-generation-strategy
我正在尝试使用本机查询进行批量插入。
@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
标识符生成器,hibernate 将静默禁用批处理 inserts/updates。
详情请见以下link: https://www.baeldung.com/jpa-hibernate-batch-insert-update#id-generation-strategy