From 46407c6763dfd0a0de1544d2ca5babfab68fd3d5 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 10 May 2016 17:29:23 +0100 Subject: [PATCH] =?UTF-8?q?Align=20JPA=20sample=20with=20Hibernate=205.1?= =?UTF-8?q?=E2=80=99s=20table=20naming?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The name of the table for a many-to-many relationship has changed in Hibernate 5.1. This commit updates the JPA sample’s import.sql accordingly. It also updates the repository integration tests to verify that the data has been imported successfully. Closes gh-5880 --- .../src/main/resources/import.sql | 16 ++++++++-------- .../JpaNoteRepositoryIntegrationTests.java | 5 +++++ .../JpaTagRepositoryIntegrationTests.java | 5 +++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/import.sql b/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/import.sql index a3d2222035..0468e3ba42 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/import.sql +++ b/spring-boot-samples/spring-boot-sample-jpa/src/main/resources/import.sql @@ -7,11 +7,11 @@ insert into note(title, body) values ('Spring Framework', 'Core support for depe insert into note(title, body) values ('Spring Integration', 'Extends the Spring programming model to support the well-known Enterprise Integration Patterns.') insert into note(title, body) values ('Tomcat', 'Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.') -insert into note_tags(notes_id, tags_id) values (1, 1) -insert into note_tags(notes_id, tags_id) values (2, 1) -insert into note_tags(notes_id, tags_id) values (3, 1) -insert into note_tags(notes_id, tags_id) values (1, 3) -insert into note_tags(notes_id, tags_id) values (2, 3) -insert into note_tags(notes_id, tags_id) values (3, 3) -insert into note_tags(notes_id, tags_id) values (4, 2) -insert into note_tags(notes_id, tags_id) values (4, 3) \ No newline at end of file +insert into note_tag(notes_id, tags_id) values (1, 1) +insert into note_tag(notes_id, tags_id) values (2, 1) +insert into note_tag(notes_id, tags_id) values (3, 1) +insert into note_tag(notes_id, tags_id) values (1, 3) +insert into note_tag(notes_id, tags_id) values (2, 3) +insert into note_tag(notes_id, tags_id) values (3, 3) +insert into note_tag(notes_id, tags_id) values (4, 2) +insert into note_tag(notes_id, tags_id) values (4, 3) diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java index 4259baa847..6c7cf862f4 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java @@ -24,6 +24,7 @@ import sample.jpa.domain.Note; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; @@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringBootTest +@Transactional public class JpaNoteRepositoryIntegrationTests { @Autowired @@ -43,6 +45,9 @@ public class JpaNoteRepositoryIntegrationTests { public void findsAllNotes() { List notes = this.repository.findAll(); assertThat(notes).hasSize(4); + for (Note note : notes) { + assertThat(note.getTags().size()).isGreaterThan(0); + } } } diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java index 3c6f66cc87..8e815ef550 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java @@ -24,6 +24,7 @@ import sample.jpa.domain.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; import static org.assertj.core.api.Assertions.assertThat; @@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringBootTest +@Transactional public class JpaTagRepositoryIntegrationTests { @Autowired @@ -43,6 +45,9 @@ public class JpaTagRepositoryIntegrationTests { public void findsAllTags() { List tags = this.repository.findAll(); assertThat(tags).hasSize(3); + for (Tag tag : tags) { + assertThat(tag.getNotes().size()).isGreaterThan(0); + } } }