#!/usr/bin/env bash # Can you actually use Propagation.NESTED with Spring Data JPA? Three attempts. set -euo pipefail set +m cd "$(dirname "$0")/.." source scripts/env.sh { echo "== attempt 1: a stock Spring Boot JPA application ==" echo "\$ java -jar $JAR" echo start_app > /dev/null curl -s "http://127.0.0.1:${APP_PORT}/tx/propagation" | python3 -c ' import json,sys v=json.load(sys.stdin)["NESTED"]["withOuterTransaction"] print(" " + v.get("exception","(no exception)")) print(" " + v.get("message",""))' echo echo "== attempt 2: nestedTransactionAllowed = true, as the message instructs ==" echo "\$ java -jar $JAR --demo.nested-allowed=true" echo start_app --demo.nested-allowed=true > /dev/null curl -s "http://127.0.0.1:${APP_PORT}/tx/propagation" | python3 -c ' import json,sys v=json.load(sys.stdin)["NESTED"]["withOuterTransaction"] print(" " + v.get("exception","(no exception)")) print(" " + v.get("message",""))' echo echo "A different message, from a second check. The savepoint manager is obtained from the" echo "object the JpaDialect returns when it begins the transaction, and Hibernate's does not" echo "implement one -- so no amount of configuration gets NESTED working here." echo echo "== attempt 3: the same propagation on a JDBC transaction manager ==" echo "\$ curl -s localhost:$APP_PORT/tx/nested-jdbc" echo curl -s "http://127.0.0.1:${APP_PORT}/tx/nested-jdbc" | python3 -m json.tool | sed 's/^/ /' echo echo "This is what NESTED is for: the nested scope rolled back to its savepoint, the outer" echo "transaction carried on and committed, and one of the two rows survived." echo echo "A savepoint is a JDBC concept. DataSourceTransactionManager holds the JDBC connection" echo "and can issue one; JpaTransactionManager holds an EntityManager and cannot. The" echo "reference documentation does say NESTED works with JDBC resource transactions -- what" echo "it does not say is that the JPA path fails, twice, with two different messages." stop_app } > docs/output/03-nested.txt 2>&1 cat docs/output/03-nested.txt