Batch Inserts In Spring Boot Style
Description: Batch inserts (in MySQL) in Spring Boot style.
Key points:
- in
application.propertiessetspring.jpa.properties.hibernate.jdbc.batch_size - in
application.propertiessetspring.jpa.properties.hibernate.generate_statistics(just to check that batching is working) - in
application.propertiesset JDBC URL withrewriteBatchedStatements=true(optimization for MySQL) - in
application.propertiesset JDBC URL withcachePrepStmts=true(enable caching and is useful if you decide to setprepStmtCacheSize,prepStmtCacheSqlLimit, etc as well; without this setting the cache is disabled) - in
application.propertiesset JDBC URL withuseServerPrepStmts=true(this way you switch to server-side prepared statements (may lead to signnificant performance boost)) - in case of using a parent-child relationship with cascade persist (e.g. one-to-many, many-to-many) then consider to set up
spring.jpa.properties.hibernate.order_inserts=trueto optimize the batching by ordering inserts - in entity, use the assigned generator since the Hibernate
IDENTITYwill cause insert batching to be disabled - if is not needed then ensure that Second Level Cache is disabled via
spring.jpa.properties.hibernate.cache.use_second_level_cache=false


