apache / apache/incubator-seata
MybatisPlus的基类insert方法不能回滚数据
- Dominant language
- Java
- Stars
- 26k
- Forks
- 8.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 4
Description
问题如下:
seata(1.30和1.42版本都有)安装配置工作正常后,经测试发现,mybatis-plus 的 BaseMapper 类里的 insert 方法,如果在插入数据时,不指定主键id,会导致插入的数据无法回滚。同时更新的数据是能正常回滚的。
具体测试类看下图的那行注释:
`
public void insertOrder(int userId, int goodsId, String goods, int count) {
GoodsOrder goodsOrder = new GoodsOrder();
// goodsOrder.setId(101); // 必须指定主键id,否则插入的记录不能回滚
goodsOrder.setUserId(userId);
goodsOrder.setGoodsId(goodsId);
goodsOrder.setGoods(goods);
goodsOrder.setCount(count);
goodsOrderMapper.insert(goodsOrder);
}
`
这是插入后不能回滚的数据证据:
触发回滚:
`
There was an unexpected error (type=Internal Server Error, status=500).
[500] during [GET] to [http://BATIS-SEATA-FEIGN-STOCK/stock/update_stock?goodsId=56&count=101] [StockFeignService#insertOrUpdateStock(int,int)]: [{"timestamp":"2022-04-19T12:54:21.572+0000","status":500,"error":"Internal Server Error","message":"库存下限错误","path":"/stock/update_stock"}]
`
数据没被回滚,还在:
`
107 398 56 北欧沙发 101
`
如下操作可以正常回滚:
1. 如果给实体实例设定id=101(即把该行注释去掉)
2. 或者如果使用 mapper.xml 里的原生SQL语句
问题描述完了,
期待你的回复!谢谢哈!
Contributor guide
Research direction
Start at the MyBatis-Plus BaseMapper insert call in the shown insertOrder method, then reproduce the Seata rollback with the generated ID case and the failing stock update request. Compare it with the explicitly assigned ID and mapper.xml native SQL cases; done means an insert without a supplied ID is removed when the distributed transaction rolls back.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- database, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100