It seems that the current version of Spring Data Hibernate JPA dialect does not support nested transaction. From my understandranding, using Spring framework, nested transactions are possible only using the JDBC (low-level) driver. Ispecting the code of Spring Data. Looking at JpaTransactionManager#setTransactionData method. The safepoint manager is set only if the current transactionData is an instance of SavepointManager.
if (transactionData instanceof SavepointManager) {
getEntityManagerHolder().setSavepointManager((SavepointManager) transactionData);
}
Using Hibernate JPA dialect it is not. Since the class org.springframework.orm.jpa.vendor.HibernateJpaDialect$SessionTransactionData does not implement org.springframework.transaction.SavepointManager. The guy who opened the issue used at the time an old Spring version: the 3.2. It seems that we would had the same limitation at that time:
PROPAGATION_NESTED uses a single physical transaction with multiple savepoints that it can roll back to. Such partial rollbacks allow an inner transaction scope to trigger a rollback for its scope, with the outer transaction being able to continue the physical transaction despite some operations having been rolled back. This setting is typically mapped onto JDBC savepoints, so will only work with JDBC resource transactions. See Spring's DataSourceTransactionManager.
Taken from Spring 3.2 tx-propagation-nested. The solution I'm proposing to reproduce the case is to use Propagation.REQUIRES_NEW. According to that. It seems that the only difference between a REQUIRES_NEW and a Nested is in what happens if the outer transaction does a rollback. But our outer transaction does not rollback. I'm going to push a pull request with such kind of test. The issue could be reopened in the future if someone discovered that is not fixed, providing a test case reproducing the case. |