Closed shangwq closed 2 years ago
@shangwq Hello, Can you provide a demo project?
it's a simple project
the main dependencies is
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
<version>5.1.0</version>
</dependency>
application.properties
mybatis.mapper-locations = classpath*:mapper/*.xml
mybatis.configuration.map-underscore-to-camel-case = true
spring.shardingsphere.props.sql-show = true
spring.shardingsphere.datasource.names = master,slave
spring.shardingsphere.datasource.master.type = com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.master.driver-class-name = com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.master.jdbc-url = jdbc:mysql://xxx:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&allowMultiQueries=true
spring.shardingsphere.datasource.master.username = xxx
spring.shardingsphere.datasource.master.password = xxx
spring.shardingsphere.datasource.slave.type = com.zaxxer.hikari.HikariDataSource
spring.shardingsphere.datasource.slave.driver-class-name = com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.slave.jdbc-url = jdbc:mysql://xxx:3306/xxx?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2b8&allowMultiQueries=true
spring.shardingsphere.datasource.slave.username = xxx
spring.shardingsphere.datasource.slave.password = xxx
Unit Test
@SpringBootApplication
@MapperScan(basePackages = {"com.example.demo"})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Transactional(rollbackFor = Exception.class)
@SpringBootTest(classes = {DemoApplication.class})
class DemoApplicationTests {
@Resource
private AddressMapper addressMapper;
@Test
void test() {
AddressModel address = new AddressModel();
address.setAddressId(111L);
address.setContactMobile("18888888888");
address.setContactName("Tom");
addressMapper.insertSelective(address);
}
}
normally when the unit test completed, the transaction will be roll back.
but actually the data Tom
was still in database, do not roll back.
when i change spring boot version to 2.4.13, the transaction can roll back successfully
Maybe it is problem of spring boot, when exception reported, spring not send a rollback
.
shardingsphere 5.1.0 and spring boot 2.6.3 has the same issue according transaction log,spring transaction management roll back transaction,but the data saved into db.
@user20161119 downgrade spring boot to 2.6.2 can fix it temporarily.
@user20161119 downgrade spring boot to 2.6.2 can fix it temporarily.
It's work,thanks
@user20161119 downgrade spring boot to 2.6.2 can fix it temporarily.
Could you explain the issue and what's the plan for the issue to fix?
thanks
@shangwq Hello, Can you provide a demo project?
@zjcnb There is a plan to fix the issue?
@user20161119 @shangwq @jingshanglu Hi, I think this problem not belong ShardingSphere
. Because, when we use @Transaction
in unit test. the isDefaultRollback(TestContext testContext)
method has problem.
@zjcnb I tested with spring boot 2.6.3 with jdbc,transaction worked as excepted,the data did not save to db
shardingsphere-jdbc-pools-test.zip
Refer to this example.
@user20161119 @shangwq @jingshanglu Hi, I think this problem not belong
ShardingSphere
. Because, when we use@Transaction
in unit test. theisDefaultRollback(TestContext testContext)
method has problem.
You said the issues is not belong Sharding-jdbc,i tested with jdbc,the transaction work as excepted, the issue is belong to sharding-jdbc?
@user20161119 @shangwq @jingshanglu Hi, I think this problem not belong
ShardingSphere
. Because, when we use@Transaction
in unit test. theisDefaultRollback(TestContext testContext)
method has problem.You said the issues is not belong Sharding-jdbc,i tested with jdbc,the transaction work as excepted, the issue is belong to sharding-jdbc?
Support your project demo please.
run junit test com.example.demo.DBServiceTest.testAdd()
\
run junit test
com.example.demo.DBServiceTest.testAdd()
Did you use ShardingSphere
for this project???
@zjcnb I tested with spring boot 2.6.3 with jdbc,transaction worked as excepted,the data did not save to db
This project do not depends on shardingSphere,I just want to verify my above question it's spring boot transaction issue or ShardingSpere issue.
shardingsphere-jdbc-pools-test.zip
Refer to this example.
upgrade spring boot version to 2.6.4 or above, will be reproduction.
use the lastest version spring boot 2.6.4 and shardingsphere 5.1.0 transaction do not roll back
ps. use spring boot 2.5.x and 2.6.x has this same problem,spring boot 2.4.x is ok