Skip to content

Commit 35ecffc

Browse files
Batch deletes (including associations)
1 parent 9ad020d commit 35ecffc

File tree

1 file changed

+2
-2
lines changed
  • HibernateSpringBootBatchDeleteOrphanRemoval

1 file changed

+2
-2
lines changed

HibernateSpringBootBatchDeleteOrphanRemoval/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
**Description:** Batch deletes in MySQL via `orphanRemoval=true`.
44

5-
**Note:** Spring `deleteAllInBatch()` and `deleteInBatch()` don't use batching and don't take advantage of `orphanRemoval=true`. 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. Using these methods for deleting a parent entities and the associated entites (children) requires explicit calls for both sides. For batching rely on `deleteAll()` or even better, on `delete()` method.
5+
**Note:** Spring `deleteAllInBatch()` and `deleteInBatch()` don't use batching and don't take advantage of `orphanRemoval=true`. 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. Using these methods for deleting parent-entities and the associated entites (child-entities) requires explicit calls for both sides. For batching rely on `deleteAll()`, `deleteAll(Iterable<? extends T> entities)` or even better, on `delete()` method. Behind the scene, `deleteAll()` methods uses `delete()`.
66

7-
**Key points for using `delete()`:**\
7+
**Key points for using `deleteAll()/delete()`:**\
88
- in this example, we have a `Author` entity and each author can have several `Book` (*one-to-many*)\
99
- first, we use `orphanRemoval=true` and `CascadeType.ALL`\
1010
- second, we dissociate all `Book` from the corresponding `Author`\

0 commit comments

Comments
 (0)