#232 - Added example to show JPA stream executions are rejected without surrounding transaction.

This commit is contained in:
Oliver Gierke
2016-12-14 15:36:24 +01:00
parent cd36f6f0da
commit 1ddfd03d84
2 changed files with 15 additions and 0 deletions

View File

@@ -10,5 +10,9 @@
<artifactId>spring-data-jpa-java8</artifactId>
<name>Spring Data JPA - Java 8 specific features</name>
<properties>
<spring-data-releasetrain.version>Ingalls-BUILD-SNAPSHOT</spring-data-releasetrain.version>
</properties>
</project>

View File

@@ -30,6 +30,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@@ -106,6 +107,16 @@ public class Java8IntegrationTests {
}
}
/**
* Query methods using streaming need to be used inside a surrounding transaction to keep the connection open while
* the stream is consumed. We simulate that not being the case by actively disabling the transaction here.
*/
@Test(expected = InvalidDataAccessApiUsageException.class)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void rejectsStreamExecutionIfNoSurroundingTransactionActive() {
repository.findAllByLastnameIsNotNull();
}
/**
* Here we demonstrate the usage of {@link CompletableFuture} as a result wrapper for asynchronous repository query
* methods. Note, that we need to disable the surrounding transaction to be able to asynchronously read the written