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
@EnableTransactionManagement
- ensure that the transaction annotation
is added on the method
@Transactional
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 code>, On the debug the Jpa's transaction processing mainly in the
JpaTransactionManager. DoBegin code>, 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 JdbcConnection
1. 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>
</property>
</bean>
Read More:
- Solve “error: failed to commit transaction” in arch Linux
- Spring configuration transaction, JUnit unit test error “failed to load ApplicationContext”
- [Java] spring transaction control configuration error, application- persstence.xml Transaction manager report red in file
- The COMMIT TRANSACTION request has no corresponding BEGIN
- After switching the tidb database, an error could not commit JDBC transaction appears from time to time
- How to cancel the commit, how to cancel the commit after git commit, and how to change the submitted content
- Error: current transaction is aborted, commands ignored until end of transaction blockp
- Failed to commit changes to dconf: the connection is closed
- SQLServerException: The server failed to resume the transaction. Desc:ab00000002
- Spring initializer error: initialization failed for ‘ https://start.spring.io ‘
- (gedit:10072): dconf-WARNING **: failed to commit changes to dconf: connection closed
- Commit failed – exit code 1 received
- Springboot + mybatis plus transaction management
- In the XML configuration file of spring jdbc.properties The connection to the database failed due to garbled code
- Common mistakes in WCF distributed development (15): Communication with the underlying transaction manager has failed.
- GitHub desktop upload file error commit failed – exit code 1 received
- Mybatis openSession.commit () manually submit data and openSession.commit (true) automatically submit data
- The Spring problem Failed to read Schema Document
- Failed to instantiate org.mybatis.spring.SqlSessionTemplate Constructor threw exception
- Spring boot running appears java.lang.IllegalStateException : Failed to load ApplicationContext