For English only, other languages will not accept.
Before report a bug, make sure you have:
Please pay attention on issues you submitted, because we maybe need more details.
If no response more than 7 days and we cannot reproduce it on current information, we will close it.
Please answer these questions before submitting your issue. Thanks!
4.0.0-RC2
Sharding-JDBC
1, The insert is committed directly.
2, Local transaction cannot be rolled back after a null pointer exception is thrown.
Example code:

Distributed transactions are enabled after the sharding-transaction-xa-core package is imported into the project.
The reason for the insert is directly committed is probably because the autoCommit property of the ShardingConnection class defaults to true and then returns false in the isHoldTransaction function of the ShardingConnection class.
Please see the sample code below.
hi, you should exclude the JtaAutoConfiguration in your project like this
@SpringBootApplication(exclude = JtaAutoConfiguration.class)
aslo @ShardingTransactionType doesn't work without sharding-transaction-jdbc-spring dependency. we haven't merge it to ShardingSphere now, you should deploy it by yourself
hi, you should exclude the
JtaAutoConfigurationin your project like this@SpringBootApplication(exclude = JtaAutoConfiguration.class)aslo @ShardingTransactionType doesn't work without sharding-transaction-jdbc-spring dependency. we haven't merge it to ShardingSphere now, you should deploy it by yourself
Thank you for your patient reply.
It finally worked when I excluded JtaAutoConfiguration from my project.
The solution is to use DataSourceTransactionManager by default after excluded JtaAutoConfiguration ?
The second question is, can I use 2PC XA transactions after excluding JtaAutoConfiguration? (Even if that means no JtaTransactionManager)
hi, you should exclude the
JtaAutoConfigurationin your project like this@SpringBootApplication(exclude = JtaAutoConfiguration.class)aslo @ShardingTransactionType doesn't work without sharding-transaction-jdbc-spring dependency. we haven't merge it to ShardingSphere now, you should deploy it by yourself
As for your statement that "@ShardingTransactionType doesn't work without sharding-transaction-jdbc-spring dependency", which version will be merged?
Currently, do we have to develop the @ShardingTransactionType aspect by ourselves?
After debugging, I found that excluding or not excluding JtaAutoConfiguration made a big difference.
Don’t exclude JtaAutoConfiguration, use JtaTransactionManager.
When commit:
1、org.springframework.transaction.support.AbstractPlatformTransactionManager#commit
2、org.springframework.transaction.jta.JtaTransactionManager#doCommit
3、com.atomikos.icatch.jta.UserTransactionManager#commit
Exclude JtaAutoConfiguration, use DataSourceTransactionManager.
When commit:
1、org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingConnection#commit
2、org.apache.shardingsphere.transaction.xa.XAShardingTransactionManager#commit
3、com.atomikos.icatch.jta.UserTransactionManager#commit
Does this mean that JtaAutoConfiguration must be excluded to ensure that sharding-jdbc controls the commit or rollback ? @cherrylzhao
Wish you a happy Spring Festival in advance !
Can someone solve my doubts?
It’s very important for me.
I still have a production problem to solve.

@KomachiSion @terrymanu @cherrylzhao
After debugging, I found that excluding or not excluding JtaAutoConfiguration made a big difference.
Don’t exclude JtaAutoConfiguration, use JtaTransactionManager.
When commit:
1、org.springframework.transaction.support.AbstractPlatformTransactionManager#commit
2、org.springframework.transaction.jta.JtaTransactionManager#doCommit
3、com.atomikos.icatch.jta.UserTransactionManager#commitExclude JtaAutoConfiguration, use DataSourceTransactionManager.
When commit:
1、org.apache.shardingsphere.shardingjdbc.jdbc.core.connection.ShardingConnection#commit
2、org.apache.shardingsphere.transaction.xa.XAShardingTransactionManager#commit
3、com.atomikos.icatch.jta.UserTransactionManager#commitDoes this mean that JtaAutoConfiguration must be excluded to ensure that sharding-jdbc controls the commit or rollback ? @cherrylzhao
If you want to use ShardingSphere XA, you need to exclude JtaTransactionManager. Because JtaTransactionManager will shutdown the Transaction control of ShardingSphere.
If use local or base of ShardingSphere, JtaTransactionManager can be excluded or not.
Currently, do we have to develop the @ShardingTransactionType aspect by ourselves?
There is no need to develop @ShardingTransactionType by yourself. But only you should clone the shardingsphere-spi-impl repo and install by yourself.
ShardingSphere use local transaction interface to integrate distributed transaction(XA and BASE).
from the spring perspective we only compatible with DataSourceTransactionManager,so JTA
TransactionMananger will conflict with us. @ShardingTransactionType is a customer annotation, it should be handled by aspect class, you can use our code of SPI project or develop by yourself.
@KomachiSion @cherrylzhao
Thank you very much for your answer.
My problem is solved.
If you want to use ShardingSphere XA, you need to exclude JtaTransactionManager. Because JtaTransactionManager will shutdown the Transaction control of ShardingSphere.
In addition, I think you need to update your official documents on this point.
Right here: https://shardingsphere.apache.org/document/current/en/manual/sharding-jdbc/usage/transaction/
this is a constraint in spring side, you can try to PR for it to become our new contributor
this is a constraint in spring side, you can try to PR for it to become our new contributor
Ok, I will
Most helpful comment
Ok, I will