Spring failed to commit the transaction

In the project, Spring JPA and Spring JDBC were used, but in the actual use, it was found that transactions in Spring JDBC were not committed, and the handling methods were mainly as follows

    ensure that transactions are enabled in the project
    ensure that the transaction annotation

is added on the method


These two points have been added in the system, but still not effective, see the spring jpa document found is, indeed, support for jpa transactions and JDBC transaction https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/orm/jpa/JpaTransactionManager.html , On the debug the Jpa's transaction processing mainly in the JpaTransactionManager. DoBegin , the execution will determine whether using JDBC transaction;

the system specifies JpaTransactionManager but does not specify jpaDialect. If not specified, it defaults to DefaultJpaDialect, while DefaultJpaDialect does not handle 0 JdbcConnection1. Therefore, the JDBC transaction could not be committed, and the solution was relatively simple. Manually specify jpaDialect as HibernateJpaDialect;

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" primary="true">
  <property name="entityManagerFactory" ref="entityManagerFactory"/> 
  <property name="jpaDialect">
    <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"></bean> 

Read More: