Skip to content

Commit 3394690

Browse files
Batch deletes via SQL cascade delete
1 parent 730c592 commit 3394690

File tree

1 file changed

+1
-1
lines changed
  • HibernateSpringBootBatchDeleteCascadeDelete

1 file changed

+1
-1
lines changed

HibernateSpringBootBatchDeleteCascadeDelete/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Description:** Batch deletes in MySQL via `ON DELETE CASCADE`. Auto-generated database schema will contain the `ON DELETE CASCADE` directive.
44

5-
**Note:** Spring `deleteAllInBatch()` and `deleteInBatch()` don't use *classical* delete batching. They trigger *bulk* operations via `Query.executeUpdate()`, therefore, the persistent context is not synchronized accordingly. 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. Both of them take advantage on `ON DELETE CASCADE` and are very efficient. For *classical* delete batching rely on `deleteAll()`, `deleteAll(Iterable<? extends T> entities)` or `delete()` method. Behind the scene, the two flavors of `deleteAll()` relies on `delete()`. Mixing batching with database automatic actions (`ON DELETE CASCADE`) will result in a partially synchronized persistent context.
5+
**Note:** Spring `deleteAllInBatch()` and `deleteInBatch()` don't use delete batching. They trigger *bulk* operations via `Query.executeUpdate()`, therefore, the persistent context is not synchronized accordingly (it is advisable to flush (before delete) and close/clear (after delete) the Persistent Context accordingly to avoid issues created by unflushed (if any) or outdated (if any) entities). 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. Both of them take advantage on `ON DELETE CASCADE` and are very efficient. For delete batching rely on `deleteAll()`, `deleteAll(Iterable<? extends T> entities)` or `delete()` method. Behind the scene, the two flavors of `deleteAll()` relies on `delete()`. Mixing batching with database automatic actions (`ON DELETE CASCADE`) will result in a partially synchronized persistent context.
66

77
**Key points:**\
88
- in this application, we have a `Author` entity and each author can have several `Book` (*one-to-many*)\

0 commit comments

Comments
 (0)