File tree 1 file changed +6
-4
lines changed
HibernateSpringBootBatchDeleteCascadeDelete/src/main/java/com/bookstore/service
1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ public void deleteAuthorsAndBooksViaDeleteAllInBatch() {
51
51
// deleting the authors will delete the books as well
52
52
@ Transactional
53
53
public void deleteAuthorsAndBooksViaDeleteInBatch () {
54
- List <Author > authors = authorRepository .findAll ( );
54
+ List <Author > authors = authorRepository .fetchAuthorsAndBooks ( 60 );
55
55
56
56
authorRepository .deleteInBatch (authors );
57
57
}
@@ -60,15 +60,17 @@ public void deleteAuthorsAndBooksViaDeleteInBatch() {
60
60
// the authors will be deleted in batches; the books will be deleted as well
61
61
@ Transactional
62
62
public void deleteAuthorsAndBooksViaDeleteAll () {
63
- authorRepository .deleteAll (); // for a collection of certain Authors use deleteAll(Iterable<? extends T> entities)
63
+ List <Author > authors = authorRepository .fetchAuthorsAndBooks (60 );
64
+
65
+ authorRepository .deleteAll (authors ); // for deleting all Author use deleteAll()
64
66
}
65
67
66
68
// good if you need to delete in a classical batch approach
67
69
// the authors will be deleted in batches; the books will be deleted as well
68
70
@ Transactional
69
71
public void deleteAuthorsAndBooksViaDelete () {
70
-
71
- List < Author > authors = authorRepository . findAll ();
72
+ List < Author > authors = authorRepository . fetchAuthorsAndBooks ( 60 );
73
+
72
74
authors .forEach (authorRepository ::delete );
73
75
}
74
76
}
You can’t perform that action at this time.
0 commit comments