I’m trying to make a bulk insert with a 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); }
I’ve added batch_size property to the application.properties file
spring.jpa.properties.hibernate.jdbc.batch_size = 50
But in the logs, I see that every insert processed separately. Is it possible to apply batching to native query?
Advertisement
Answer
If the entities use GenerationType.IDENTITY
identifier generator, hibernate will silently disable batch inserts/updates.
Please find the following link for the details: https://www.baeldung.com/jpa-hibernate-batch-insert-update#id-generation-strategy