diff --git a/persistence-modules/spring-data-jpa-repo-3/src/main/java/com/baeldung/spring/data/jpa/listrepositories/entity/Library.java b/persistence-modules/spring-data-jpa-repo-3/src/main/java/com/baeldung/spring/data/jpa/listrepositories/entity/Library.java index 04c0ad5e0a..724adc3aad 100644 --- a/persistence-modules/spring-data-jpa-repo-3/src/main/java/com/baeldung/spring/data/jpa/listrepositories/entity/Library.java +++ b/persistence-modules/spring-data-jpa-repo-3/src/main/java/com/baeldung/spring/data/jpa/listrepositories/entity/Library.java @@ -19,7 +19,7 @@ public class Library { private List addresses = new ArrayList<>(); @ElementCollection(targetClass = String.class, fetch = FetchType.EAGER) - @CollectionTable(name = "book", joinColumns = @JoinColumn(name = "library_id")) + @CollectionTable(name = "books", joinColumns = @JoinColumn(name = "library_id")) @Column(name = "book", nullable = false) private List books = new ArrayList<>(); diff --git a/persistence-modules/spring-data-jpa-repo-3/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-repo-3/src/main/resources/application.properties index cd6dbe3994..37f37d548d 100644 --- a/persistence-modules/spring-data-jpa-repo-3/src/main/resources/application.properties +++ b/persistence-modules/spring-data-jpa-repo-3/src/main/resources/application.properties @@ -1,5 +1,5 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.jpa.hibernate.ddl-auto=none - +spring.jpa.generate-ddl=true logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE diff --git a/persistence-modules/spring-data-jpa-repo-3/src/test/java/com/baeldung/spring/data/jpa/listrepositories/repository/BookPagingAndSortingRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-repo-3/src/test/java/com/baeldung/spring/data/jpa/listrepositories/repository/BookPagingAndSortingRepositoryIntegrationTest.java index 8f34e43e3f..9ea865c04f 100644 --- a/persistence-modules/spring-data-jpa-repo-3/src/test/java/com/baeldung/spring/data/jpa/listrepositories/repository/BookPagingAndSortingRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-repo-3/src/test/java/com/baeldung/spring/data/jpa/listrepositories/repository/BookPagingAndSortingRepositoryIntegrationTest.java @@ -21,13 +21,13 @@ public class BookPagingAndSortingRepositoryIntegrationTest { @Test public void givenDbContainsBooks_whenfindBooksByAuthor_thenReturnBooksByAuthor() { - Book book1 = new Book("Spring Data", "John Doe", "1234567890"); - Book book2 = new Book("Spring Data 2", "John Doe", "1234567891"); - Book book3 = new Book("Spring Data 3", "John Doe", "1234567892"); + Book book1 = new Book("Spring Data", "John Miller", "1234567890"); + Book book2 = new Book("Spring Data 2", "John Miller", "1234567891"); + Book book3 = new Book("Spring Data 3", "John Miller", "1234567892"); bookPagingAndSortingRepository.saveAll(Arrays.asList(book1, book2, book3)); Pageable pageable = PageRequest.of(0, 2, Sort.by("title").descending()); - List books = bookPagingAndSortingRepository.findBooksByAuthor("John Doe", pageable); + List books = bookPagingAndSortingRepository.findBooksByAuthor("John Miller", pageable); Assertions.assertEquals(2, books.size()); Assertions.assertEquals(book3.getId(), books.get(0).getId()); Assertions.assertEquals(book2.getId(), books.get(1).getId());