Skip to content

Commit 45fea0e

Browse files
committed
2 parents 2def4fc + a1f11a1 commit 45fea0e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

HibernateSpringBootBatchDeleteCascadeDelete/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
**[How To Batch Deletes In MySQL Via SQL "on delete cascade"](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchDeleteCascadeDelete)**
1+
**[How To Batch Deletes In MySQL Via SQL "ON DELETE CASCADE"](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchDeleteCascadeDelete)**
22

3-
**Description:** Batch deletes in MySQL via `on delete cascade`. Auto-generated database schema will contain `ON DELETE CASCADE` directive.
3+
**Description:** Batch deletes in MySQL via `ON DELETE CASCADE`. Auto-generated database schema will contain `ON DELETE CASCADE` directive.
44

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.
5+
**Note:** Spring `deleteAllInBatch()` and `deleteInBatch()` don't use *classical* delete 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. Both of them take advantage on `ON DELETE CASCADE`. 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()`.
66

77
**Key points:**\
8-
- in this example, we have a `Tournament` entity and each tournament can have several `TennisPlayer` (*one-to-many*)\
8+
- in this application, we have a `Author` entity and each author can have several `Book` (*one-to-many*)\
99
- first, we remove `orphanRemoval` or set it to `false`\
1010
- second, we use only `CascadeType.PERSIST` and `CascadeType.MERGE`\
1111
- third, we set `@OnDelete(action = OnDeleteAction.CASCADE)` next to `@OneToMany`\
1212
- fourth, we set `spring.jpa.properties.hibernate.dialect` to `org.hibernate.dialect.MySQL5InnoDBDialect`\
13-
- fifth, we use the Spring `delete()` method to delete all `Tournament`
13+
- fifth, we run through each `deleteFoo()` method
1414

1515
**Output example:**
1616

17-
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootBatchDeleteCascadeDelete/batch_delete.png)
17+
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootBatchDeleteCascadeDelete/batch%20delete%20via%20SQL%20cascade%20delete.png)
1818

1919
-------------------------------
2020

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1086,23 +1086,23 @@ A `Previous Page` button can be implemented easily based on the first record.
10861086

10871087
-----------------------------------------------------------------------------------------------------------------------
10881088

1089-
78. **[How To Batch Deletes In MySQL Via SQL "on delete cascade"](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchDeleteCascadeDelete)**
1089+
78. **[How To Batch Deletes In MySQL Via SQL "ON DELETE CASCADE"](https://github.com/AnghelLeonard/Hibernate-SpringBoot/tree/master/HibernateSpringBootBatchDeleteCascadeDelete)**
10901090

1091-
**Description:** Batch deletes in MySQL via `on delete cascade`. Auto-generated database schema will contain `ON DELETE CASCADE` directive.
1091+
**Description:** Batch deletes in MySQL via `ON DELETE CASCADE`. Auto-generated database schema will contain `ON DELETE CASCADE` directive.
10921092

1093-
**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.
1093+
**Note:** Spring `deleteAllInBatch()` and `deleteInBatch()` don't use *classical* delete 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. Both of them take advantage on `ON DELETE CASCADE`. 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()`.
10941094

10951095
**Key points:**\
1096-
- in this example, we have a `Tournament` entity and each tournament can have several `TennisPlayer` (*one-to-many*)\
1096+
- in this application, we have a `Author` entity and each author can have several `Book` (*one-to-many*)\
10971097
- first, we remove `orphanRemoval` or set it to `false`\
10981098
- second, we use only `CascadeType.PERSIST` and `CascadeType.MERGE`\
10991099
- third, we set `@OnDelete(action = OnDeleteAction.CASCADE)` next to `@OneToMany`\
11001100
- fourth, we set `spring.jpa.properties.hibernate.dialect` to `org.hibernate.dialect.MySQL5InnoDBDialect`\
1101-
- fifth, we use the Spring `delete()` method to delete all `Tournament`
1101+
- fifth, we run through each `deleteFoo()` method
11021102

11031103
**Output example:**
11041104

1105-
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootBatchDeleteCascadeDelete/batch_delete.png)
1105+
![](https://github.com/AnghelLeonard/Hibernate-SpringBoot/blob/master/HibernateSpringBootBatchDeleteCascadeDelete/batch%20delete%20via%20SQL%20cascade%20delete.png)
11061106

11071107
-----------------------------------------------------------------------------------------------------------------------
11081108

0 commit comments

Comments
 (0)