Skip to content

Commit a0f2584

Browse files
Update README.md
1 parent d04fdb2 commit a0f2584

File tree

1 file changed

+14
-0
lines changed
  • HibernateSpringBootBatchDeleteOrphanRemoval

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1+
**[How To Batch Deletes In MySQL Via orphanRemoval=true](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchDeleteOrphanRemoval)**
12

3+
**Description:** Batch deletes in MySQL via `orphanRemoval=true`.
4+
5+
**Note:** Spring `deleteAllInBatch()` and `deleteInBatch()` don't use batching. The first one simply triggers a `delete from entity_name` statement, while the second one triggers a `delete from entity_name where id=? or id=? or id=? ...` statement. Rely on `delete()` method.
6+
7+
**Key points:**\
8+
- in this example, we have a `Tournament` entity and each tournament can have several `TennisPlayer` (*one-to-many*)\
9+
- first, we dissociate all `TennisPlayer` from the corresponding `Tournament`\
10+
- second, we explicitly (manually) flush the persistent context (this will delete in batch all `TennisPlayer` thanks to `orphanRemoval=true`; if this is set to `false`, you will obtain a bunch of updates instead of deletes)\
11+
- third, we delete all `Tournament` via the `delete()` method (since we have dissaciated all `TennisPlayer`, the `Tournament` deletion will take advantage of batching as well)
12+
13+
**Output example:**
14+
15+
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootBatchDeleteOrphanRemoval/batch_delete.png)

0 commit comments

Comments
 (0)