Skip to content

Commit 1b7536f

Browse files
committed
Merge branch '2.5.x'
Closes gh-28160
2 parents e31e02a + 1c139b1 commit 1b7536f

File tree

2 files changed

+5
-2
lines changed
  • spring-boot-project
    • spring-boot-docs/src/docs/asciidoc/features
    • spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa

2 files changed

+5
-2
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/testing.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ include::{docs-java}/features/testing/springbootapplications/autoconfiguredsprin
490490
----
491491

492492
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.
493-
If you want to use `TestEntityManager` outside of `@DataJpaTest` instances, you can also use the `@AutoConfigureTestEntityManager` annotation.
493+
494+
TIP: `TestEntityManager` can also be auto-configured to any of your Spring-based test class by adding `@AutoConfigureTestEntityManager`.
495+
When doing so, make sure that your test is running in a transaction, for instance by adding `@Transactional` on your test class or method.
496+
494497
A `JdbcTemplate` is also available if you need that.
495498
The following example shows the `@DataJpaTest` annotation in use:
496499

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public <T> T getId(Object entity, Class<T> idType) {
234234
*/
235235
public final EntityManager getEntityManager() {
236236
EntityManager manager = EntityManagerFactoryUtils.getTransactionalEntityManager(this.entityManagerFactory);
237-
Assert.state(manager != null, "No transactional EntityManager found");
237+
Assert.state(manager != null, "No transactional EntityManager found, is your test running in a transactional?");
238238
return manager;
239239
}
240240

0 commit comments

Comments
 (0)