Skip to content

Commit d294278

Browse files
committed
Fetch association in batches
1 parent c31f782 commit d294278

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

HibernateSpringBootLoadBatchAssociation/src/main/java/com/bookstore/MainApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public static void main(String[] args) {
2020
@Bean
2121
public ApplicationRunner init() {
2222
return args -> {
23-
// System.out.println("\n\nLoad authors with books:");
24-
// bookstoreService.displayAuthorsAndBooks();
23+
System.out.println("\n\nLoad authors with books:");
24+
bookstoreService.displayAuthorsAndBooks();
2525

2626
System.out.println("\n\nLoad books with authors:");
2727
bookstoreService.displayBooksAndAuthors();

HibernateSpringBootLoadBatchAssociation/src/main/java/com/bookstore/entity/Author.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Author implements Serializable {
2828

2929
@OneToMany(cascade = CascadeType.ALL,
3030
mappedBy = "author", orphanRemoval = true)
31-
//@BatchSize(size = 3)
31+
@BatchSize(size = 3)
3232
private List<Book> books = new ArrayList<>();
3333

3434
public void addBook(Book book) {

HibernateSpringBootLoadBatchAssociation/src/main/java/com/bookstore/entity/Book.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public void setAuthor(Author author) {
5959

6060
@Override
6161
public boolean equals(Object obj) {
62-
62+
6363
if (this == obj) {
6464
return true;
6565
}
66-
66+
6767
if (getClass() != obj.getClass()) {
6868
return false;
6969
}
70-
70+
7171
return id != null && id.equals(((Book) obj).id);
7272
}
7373

@@ -80,5 +80,5 @@ public int hashCode() {
8080
public String toString() {
8181
return "Book{" + "id=" + id + ", title=" + title + ", isbn=" + isbn + '}';
8282
}
83-
83+
8484
}

0 commit comments

Comments
 (0)