Closed lordofthemoon closed 5 years ago
Could you provide a small reproduce project via GitHub?
Hi, sorry for the delay. I've now cut down my project to something that is minimal but still shows the problem. I don't use git and couldn't figure out how to upload the whole project, so I zipped the Eclipse project and have uploaded it to https://github.com/lordofthemoon/mybatisTransactionTest
Note: this is a web application (war file) that we deploy on a Wildfly 9 server. You'll need to create a SQL Server database and run schema.sql to create the required table. You'll also need to set your database URL and credentials in the honorary.properties file (in src/main/resources).
@lordofthemoon Please add configuration as follow for getting more detail informations.
logging.level.org.springframework.jdbc=TRACE
@lordofthemoon
I found a reason that commit a transaction. The Spring Boot use JTA transaction management under Java EE(Jakarta EE) environment by default settings. But the DataSource
that created via Spring Boot can not join it.
You can select a solution as follows:
DataSource
managed by WildflyYou can disable the JTA transaction management as follow:
spring.jta.enabled=false
For details, see https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/htmlsingle/#boot-features-jta.
DataSource
managed by WildflyYou can use the a DataSource
managed by Wildfly.
spring.datasource.jndi-name=java:jboss/datasources/demo
For details, see https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference/htmlsingle/#boot-features-connecting-to-a-jndi-datasource
Note: How to configure a DataSource
(need to enable JTA) on Wildfly, see https://docs.jboss.org/author/display/WFLY9/DataSource+configuration?_sscc=t.
Hi @kazuki43zoo - I tried this with the example application I provided above. I added a line:
spring.jta.enabled=false
to honorary.properties but the row was still added to the database table, and wasn't rolled back as expected. I also tried creating a DataSource in Wildfly and configure the application to use that, but also got the same issue.
I added the additional trace line to the logging and this is the output:
2019-10-28 15:07:53,380 INFO [its.hon.ServletInitializer] (ServerService Thread Pool -- 171) Started ServletInitializer in 2.803 seconds (JVM running for 776.493)
2019-10-28 15:08:00,955 TRACE [org.springframework.transaction.interceptor.TransactionInterceptor] (default task-2) Getting transaction for [its.hon.service.DataMigrationProcessor.test]
2019-10-28 15:08:00,961 DEBUG [its.hon.service.DataMigrationProcessor] (default task-2) test::entering
2019-10-28 15:08:00,963 INFO [its.hon.TransactionDebugUtils] (default task-2) [+] DataMigrationProcessor.test
2019-10-28 15:08:00,978 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] (default task-2) Fetching JDBC Connection from DataSource
2019-10-28 15:08:01,010 TRACE [org.springframework.transaction.interceptor.TransactionInterceptor] (default task-2) Completing transaction for [its.hon.service.DataMigrationProcessor.test] after exception: java.lang.RuntimeException
2019-10-28 15:08:01,010 TRACE [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] (default task-2) Applying rules to determine whether transaction should rollback on java.lang.RuntimeException
2019-10-28 15:08:01,010 TRACE [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] (default task-2) Winning rollback rule is: null
2019-10-28 15:08:01,010 TRACE [org.springframework.transaction.interceptor.RuleBasedTransactionAttribute] (default task-2) No relevant rollback rule found: applying default rules
Could you please review?
@lordofthemoon
In my env, I can resolve this issue by my suggestion solution(spring.jta.enabled=false
). Could you provide latest your project(= workaround applied project) via GitHub?
Ah, my apologies, it looks like I had missed a quirk of my configuration. The workaround that you suggested does now work.
PS: If you want to add it to my Stack Overflow question https://stackoverflow.com/questions/58302423/spring-boot-with-mybatis-doesnt-rollback-transactions, I'll be happy to accept your answer
@lordofthemoon
I've added my answer on Stack Overflow!
Hi @lordofthemoon @kazuki43zoo can you please uploaded the working code , i have tried this but failed , found row inserted into the table .
Hi, I've described this problem at StackOverflow: https://stackoverflow.com/questions/58302423/spring-boot-with-mybatis-doesnt-rollback-transactions
I have an application where I expect a MyBatis transaction to rollback when taking part in a Spring transaction, and it never happens. If it helps, if I ramp up TRACE logging on org.springframework.transaction.interceptor I see the following: