I've applied pretty much all solutions posted here on SO regarding this issue but nothing worked.
My application.properties:
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?logger=com.mysql.jdbc.log.Slf4JLogger&rewriteBatchedStatements=true&profileSQL=true&autoReconnect=true&useSSL=false
spring.datasource.username=user
spring.datasource.password=secret
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.jdbc.batch_size = 100
spring.jpa.hibernate.order_inserts = true
spring.jpa.hibernate.order_updates = true
logging.level.root=info
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5p) %gray(%c{0}::%M) - %m%n
My EntityRepository:
@Repository
public interface EntityRepository extends CrudRepository<Entity, Long> { }
My Entity:
@Data @Entity
public class Entity {
@Id
@GeneratedValue(generator = "generator")
@GenericGenerator(name = "generator", strategy = "increment")
private Long id;
private Long attr;
}
And the simplified code that calls repository:
int batchSize = 100;
List<Entity> batchEntities = new ArrayList<>();
for(Entity entity : entities) {
batchEntities.add(entity);
if(batchEntities.size() >= batchSize) {
entityRepository.saveAll(batchEntities);
batchEntities.clear();
}
}
What I've done:
As per this SO question I've enabled the profileSQL=true option and the log produces several individual inserts. Also, I've enabled global logging on SQL server and it too produces sequence of individual inserts.
As per this another SO question and yet another SO question I've made sure that batch_size is set in the application.properties file and although I have no parent-child relationship I've also tried to use the order_inserts and order_updates. Also, I've enabled the rewriteBatchedStatements=true option and use the saveAll(...) method.
I've also tried to ditch the premade CrudRepository and my a custom one, by flushing after every batchSize-th persist.
Nothing above helped.
spring.jpa.hibernate.order_updateswon't do anything (the same applies to the other properties). Instead usespring.jpa.properties.hibernate.order_updates(same applies to the other custom hibernate properties as well).