Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested transaction in Spring app with JPA (postgres)

Is it possible to have PROPAGATION_NESTED in @Transactional() with JPA using postgres? I am getting:

org.springframework.transaction.NestedTransactionNotSupportedException:
JpaDialect does not support savepoints - check your JPA provider's capabilities

I tried:

@Bean
public PlatformTransactionManager transactionManager() {
    JpaTransactionManager transactionManager = new JpaTransactionManager();
    transactionManager.setEntityManagerFactory(entityManagerFactory()
                .getObject());
    transactionManager.setNestedTransactionAllowed(true);
    return transactionManager;
}

But with no success.

like image 373
Semyon Danilov Avatar asked Jun 20 '16 16:06

Semyon Danilov


People also ask

Is nested transactions supported by Spring?

Not all transaction managers support nested transactions. Spring supports this out of the box only with the JDBC DataSourceTransactionManager, which is what we'll cover.

What does @transactional do in JPA?

The @Transactional annotation is the metadata that specifies the semantics of the transactions on a method. We have two ways to rollback a transaction: declarative and programmatic. In the declarative approach, we annotate the methods with the @Transactional annotation.

Does Saveandflush commit transaction?

No. It doesn't flush data directly to a database until and unless we explicitly call flush and commit method. It's flush directly flush data to a database. It doesn't flush data directly to a database, therefore, changes will not be visible outside the transaction unless we explicitly call commit() in this transaction.


1 Answers

I am assuming that you are using Hibernate. NESTED transactions is not possible with Hibernate.

enter image description here

In the following code excerpt, spring sets savePointManager. But there is no class implementing SavepointManager in Hibernate.

like image 110
Halil Avatar answered Sep 19 '22 12:09

Halil