File tree Expand file tree Collapse file tree 3 files changed +10
-1
lines changed
spring-boot-docs/src/main/asciidoc
spring-boot-test-autoconfigure/src
test/java/org/springframework/boot/test/autoconfigure/orm/jpa Expand file tree Collapse file tree 3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -5204,7 +5204,8 @@ Data JPA tests may also inject a
52045204{sc-spring-boot-test-autoconfigure}/orm/jpa/TestEntityManager.{sc-ext}[`TestEntityManager`]
52055205bean which provides an alternative to the standard JPA `EntityManager` specifically
52065206designed for tests. If you want to use `TestEntityManager` outside of `@DataJpaTests` you
5207- can also use the `@AutoConfigureTestEntityManager` annotation.
5207+ can also use the `@AutoConfigureTestEntityManager` annotation. A `JdbcTemplate` is also
5208+ available should you need that.
52085209
52095210[source,java,indent=0]
52105211----
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration
88org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration,\
99org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
1010org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\
11+ org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration,\
1112org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration,\
1213org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration,\
1314org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration
Original file line number Diff line number Diff line change 2828import org .springframework .boot .autoconfigure .flyway .FlywayAutoConfiguration ;
2929import org .springframework .boot .autoconfigure .liquibase .LiquibaseAutoConfiguration ;
3030import org .springframework .context .ApplicationContext ;
31+ import org .springframework .jdbc .core .JdbcTemplate ;
3132import org .springframework .test .context .junit4 .SpringRunner ;
3233
3334import static org .assertj .core .api .Assertions .assertThat ;
@@ -49,6 +50,9 @@ public class DataJpaTestIntegrationTests {
4950 @ Autowired
5051 private TestEntityManager entities ;
5152
53+ @ Autowired
54+ private JdbcTemplate jdbcTemplate ;
55+
5256 @ Autowired
5357 private ExampleRepository repository ;
5458
@@ -72,6 +76,9 @@ public void testEntityManagerPersistAndGetId() throws Exception {
7276 Long id = this .entities .persistAndGetId (new ExampleEntity ("spring" , "123" ),
7377 Long .class );
7478 assertThat (id ).isNotNull ();
79+ String reference = this .jdbcTemplate .queryForObject (
80+ "SELECT REFERENCE FROM EXAMPLE_ENTITY WHERE ID = ?" , new Object [] {id }, String .class );
81+ assertThat (reference ).isEqualTo ("123" );
7582 }
7683
7784 @ Test
You can’t perform that action at this time.
0 commit comments