Skip to content

Commit 9b5881b

Browse files
Batch inserts via EntityManager
1 parent 333c033 commit 9b5881b

File tree

1 file changed

+2
-0
lines changed
  • HibernateSpringBootBatchInsertsEntityManager

1 file changed

+2
-0
lines changed

HibernateSpringBootBatchInsertsEntityManager/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
**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)`.
55

6+
If you want to execute a batch per transaction (to avoid long-running transaction and lose all batches in case of failure) then check this [example](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchInsertsEntityManagerBatchPerTransaction).
7+
68
**Key points:**
79
- in `application.properties` set `spring.jpa.properties.hibernate.jdbc.batch_size`
810
- in `application.properties` set `spring.jpa.properties.hibernate.generate_statistics` (just to check that batching is working)

0 commit comments

Comments
 (0)