Commit 46407c67 authored by Andy Wilkinson's avatar Andy Wilkinson

Align JPA sample with Hibernate 5.1’s table naming

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
parent 3ad334ed
...@@ -7,11 +7,11 @@ insert into note(title, body) values ('Spring Framework', 'Core support for depe ...@@ -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 ('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(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_tag(notes_id, tags_id) values (1, 1)
insert into note_tags(notes_id, tags_id) values (2, 1) insert into note_tag(notes_id, tags_id) values (2, 1)
insert into note_tags(notes_id, tags_id) values (3, 1) insert into note_tag(notes_id, tags_id) values (3, 1)
insert into note_tags(notes_id, tags_id) values (1, 3) insert into note_tag(notes_id, tags_id) values (1, 3)
insert into note_tags(notes_id, tags_id) values (2, 3) insert into note_tag(notes_id, tags_id) values (2, 3)
insert into note_tags(notes_id, tags_id) values (3, 3) insert into note_tag(notes_id, tags_id) values (3, 3)
insert into note_tags(notes_id, tags_id) values (4, 2) insert into note_tag(notes_id, tags_id) values (4, 2)
insert into note_tags(notes_id, tags_id) values (4, 3) insert into note_tag(notes_id, tags_id) values (4, 3)
\ No newline at end of file
...@@ -24,6 +24,7 @@ import sample.jpa.domain.Note; ...@@ -24,6 +24,7 @@ import sample.jpa.domain.Note;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@Transactional
public class JpaNoteRepositoryIntegrationTests { public class JpaNoteRepositoryIntegrationTests {
@Autowired @Autowired
...@@ -43,6 +45,9 @@ public class JpaNoteRepositoryIntegrationTests { ...@@ -43,6 +45,9 @@ public class JpaNoteRepositoryIntegrationTests {
public void findsAllNotes() { public void findsAllNotes() {
List<Note> notes = this.repository.findAll(); List<Note> notes = this.repository.findAll();
assertThat(notes).hasSize(4); assertThat(notes).hasSize(4);
for (Note note : notes) {
assertThat(note.getTags().size()).isGreaterThan(0);
}
} }
} }
...@@ -24,6 +24,7 @@ import sample.jpa.domain.Tag; ...@@ -24,6 +24,7 @@ import sample.jpa.domain.Tag;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -34,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest @SpringBootTest
@Transactional
public class JpaTagRepositoryIntegrationTests { public class JpaTagRepositoryIntegrationTests {
@Autowired @Autowired
...@@ -43,6 +45,9 @@ public class JpaTagRepositoryIntegrationTests { ...@@ -43,6 +45,9 @@ public class JpaTagRepositoryIntegrationTests {
public void findsAllTags() { public void findsAllTags() {
List<Tag> tags = this.repository.findAll(); List<Tag> tags = this.repository.findAll();
assertThat(tags).hasSize(3); assertThat(tags).hasSize(3);
for (Tag tag : tags) {
assertThat(tag.getNotes().size()).isGreaterThan(0);
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment