Clarify use of @AutoConfigureTestEntityManager

This commit makes it clearer that, when using
@AutoConfigureTestEntityManager outside of @DataJpaTest, any tests using
the test entity manager must be @Transactional.

See gh-28086
This commit is contained in:
Leo Li
2021-09-22 11:43:08 +08:00
committed by Stephane Nicoll
parent 3824512357
commit 70f64f2c26
2 changed files with 4 additions and 3 deletions

View File

@@ -7634,7 +7634,7 @@ If that is not what you want, you can disable transaction management for a test
----
Data JPA tests may also inject a {spring-boot-test-autoconfigure-module-code}/orm/jpa/TestEntityManager.java[`TestEntityManager`] bean, which provides an alternative to the standard JPA `EntityManager` that is specifically designed for tests.
If you want to use `TestEntityManager` outside of `@DataJpaTest` instances, you can also use the `@AutoConfigureTestEntityManager` annotation.
If you want to use `TestEntityManager` outside of `@DataJpaTest` instances, you can also use the `@AutoConfigureTestEntityManager` annotation, and make sure to use the `@Transactional` annotation on your test class or method.
A `JdbcTemplate` is also available if you need that.
The following example shows the `@DataJpaTest` annotation in use: