From 50e0bb2d9ca3d4d649ec55d135381102c6b6737d Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 25 May 2016 11:28:16 +0200 Subject: [PATCH] Improve DataJpaTest documentation As `@DataJpaTest` is meta-annotated with `@Transactional`, all data jpa tests are transactional and rollback at the end of each test. It is possible to tune that in many ways, including disabling the transaction per test or per test class. This commit improves the doc to explain those concepts. Closes gh-5993 --- .../main/asciidoc/spring-boot-features.adoc | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 034c70bc79..cb421abc24 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -4880,6 +4880,27 @@ configure an in-memory embedded database, scan for `@Entity` classes and configu Data JPA repositories. Regular `@Component` beans will not be loaded into the `ApplicationContext`. +Data JPA tests are transactional and rollback at the end of each test by default, +see the {spring-reference}#testcontext-tx-enabling-transactions [relevant section] in the +Spring Reference Documentation for more details. If that's not what you want, you can +disable transaction management for a test or for the whole class as follows: + +[source,java,indent=0] +---- + import org.junit.*; + import org.junit.runner.*; + import org.springframework.boot.test.autoconfigure.orm.jpa.*; + import org.springframework.test.context.transaction.TestTransaction; + import org.springframework.transaction.annotation.Propagation; + + @RunWith(SpringRunner.class) + @DataJpaTest + @Transactional(propagation = Propagation.NOT_SUPPORTED) + public class ExampleNonTransactionalTests { + + } +---- + Data JPA tests may also inject a {sc-spring-boot-test-autoconfigure}/orm/jpa/TestEntityManager.{sc-ext}[`TestEntityManager`] bean which provides an alternative to the standard JPA `EntityManager` specifically