Commit 50e0bb2d authored by Stephane Nicoll's avatar Stephane Nicoll

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
parent ccd19ce2
...@@ -4880,6 +4880,27 @@ configure an in-memory embedded database, scan for `@Entity` classes and configu ...@@ -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 Data JPA repositories. Regular `@Component` beans will not be loaded into the
`ApplicationContext`. `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 Data JPA tests may also inject a
{sc-spring-boot-test-autoconfigure}/orm/jpa/TestEntityManager.{sc-ext}[`TestEntityManager`] {sc-spring-boot-test-autoconfigure}/orm/jpa/TestEntityManager.{sc-ext}[`TestEntityManager`]
bean which provides an alternative to the standard JPA `EntityManager` specifically bean which provides an alternative to the standard JPA `EntityManager` specifically
......
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