Skip to content

Commit e11d4f7

Browse files
Update README.md
1 parent aff4978 commit e11d4f7

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,23 @@
6464

6565
-----------------------------------------------------------------------------------------------------------------------
6666

67-
5. **[How To Batch Inserts Via EntityManager In MySQL](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchInsertsEntityManager)**
67+
5. **[Batch Inserts Via EntityManager in MySQL](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchInsertsEntityManager)**
6868

6969
**Description:** Batch inserts via `EntityManager` in MySQL. This way you can easily control the `flush()` and `clear()` of the persistence context (1st level cache). This is not possible via SpringBoot, `saveAll(Iterable<S> entities)`. Another advantage is that you can call `persist()` instead of `merge()` - this is used behind the scene by the SpringBoot `saveAll(Iterable<S> entities)` and `save(S entity)`.
7070

7171
**Key points:**\
72-
- in application.properties set `spring.jpa.properties.hibernate.jdbc.batch_size`\
73-
- in application.properties set `spring.jpa.properties.hibernate.generate_statistics` (just to check that batching is working)\
74-
- in application.properties set JDBC URL with `rewriteBatchedStatements=true` (optimization for MySQL)\
75-
- in application.properties set JDBC URL with `cachePrepStmts=true` (enable caching and is useful if you decide to set `prepStmtCacheSize`, `prepStmtCacheSqlLimit`, etc as well; without this setting the cache is disabled)\
76-
- in application.properties set JDBC URL with `useServerPrepStmts=true` (this way you switch to server-side prepared statements (may lead to signnificant performance boost))\
72+
- in `application.properties` set `spring.jpa.properties.hibernate.jdbc.batch_size`\
73+
- in `application.properties` set `spring.jpa.properties.hibernate.generate_statistics` (just to check that batching is working)\
74+
- in `application.properties` set JDBC URL with `rewriteBatchedStatements=true` (optimization for MySQL)\
75+
- in `application.properties` set JDBC URL with `cachePrepStmts=true` (enable caching and is useful if you decide to set `prepStmtCacheSize`, `prepStmtCacheSqlLimit`, etc as well; without this setting the cache is disabled)\
76+
- in `application.properties` set JDBC URL with `useServerPrepStmts=true` (this way you switch to server-side prepared statements (may lead to signnificant performance boost))\
7777
- 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=true` to optimize the batching by ordering inserts\
7878
- in entity, use the [assigned generator](https://vladmihalcea.com/how-to-combine-the-hibernate-assigned-generator-with-a-sequence-or-an-identity-column/) since MySQL `IDENTITY` will cause batching to be disabled\
79-
- in DAO, flush and clear the persistence context from time to time. This way you avoid to "overwhelm" the persistence context.
79+
- in DAO, flush and clear the persistence context from time to time; this way you avoid to "overwhelm" the persistence context\
80+
- if is not needed then ensure that Second Level Cache is disabled via `spring.jpa.properties.hibernate.cache.use_second_level_cache=false`
8081

8182
**Output example:**
82-
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootBatchInsertsEntityManager/sample.png)
83+
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootBatchInsertsEntityManager/batch%20inserts%20via%20EntityManager.png)
8384

8485
-----------------------------------------------------------------------------------------------------------------------
8586

0 commit comments

Comments
 (0)