确认

  • [x] 我使用的版本是最新版, 并且使用插件确认过项目里无依赖版本冲突
  • [x] 我已经在 issue 中搜索过, 确认问题没有被提出过
  • [x] 我已经修改标题, 将标题中的 描述 替换为遇到的问题(不得删除 描述 前面的部分)

当前程序版本

3.5.12

问题描述

model 设置 IdType.AUTO,手动设置了id,插入的id是手动设置的id,但是对象中的id自增了。

                List<AccountStepRelation> list = new ArrayList<>();                
                list.add(AccountStepRelation.builder().id(1950354444940083200L).accountId(1L).stepId(0L).companyId(1L).build());                
                list.add(AccountStepRelation.builder().id(1950354444940083201L).accountId(1L).stepId(1111L).companyId(1L).build());                
                list.add(AccountStepRelation.builder().id(1950354444940083202L).accountId(1L).stepId(2222L).companyId(1L).build());                
                list.add(AccountStepRelation.builder().id(1950354444940083203L).accountId(1L).stepId(3333L).companyId(1L).build());                
                list.add(AccountStepRelation.builder().id(1950354444940083204L).accountId(1L).stepId(4444L).companyId(1L).build());                
                list.add(AccountStepRelation.builder().id(1950354444940083205L).accountId(1L).stepId(5555L).companyId(1L).build());                
                accountStepRelationService.saveBatch(list);                
                for (AccountStepRelation l : list) {
                        System.out.println(l.getId());
                }

代码设置的id尾号为200~205

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "sys_account_step_relation")
public class AccountStepRelation extends Model<AccountStepRelation> {
    private static final long serialVersionUID = 199434430365352520L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;


    @TableField(value = "account_id")
    private Long accountId;


    @TableField(value = "step_id")
    private Long stepId;


    @TableField(value = "company_id", fill = FieldFill.INSERT)
    private Long companyId;
}

CREATE TABLE `sys_account_step_relation` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '账号和步骤的关联关系',
  `account_id` bigint NOT NULL COMMENT '账号id',
  `step_id` bigint NOT NULL COMMENT '步骤id',
  `company_id` bigint NOT NULL COMMENT '公司id',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `udx_1` (`account_id`,`step_id`,`company_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='账号-步骤关联关系表';

详细堆栈日志


2025-08-19 09:59:14.992 DEBUG  [nio-8088-exec-1] com.demo.mapper.AccountStepRelationMapper.insert:135  : ==>  Preparing: INSERT INTO sys_account_step_relation ( id, account_id, step_id, company_id ) VALUES ( ?, ?, ?, ? )
2025-08-19 09:59:14.995 DEBUG  [nio-8088-exec-1] com.demo.mapper.AccountStepRelationMapper.insert:135  : ==> Parameters: 1950354444940083200(Long), 1(Long), 0(Long), 1(Long)
2025-08-19 09:59:15.153 DEBUG  [nio-8088-exec-1] com.demo.mapper.AccountStepRelationMapper.insert:135  : ==> Parameters: 1950354444940083201(Long), 1(Long), 1111(Long), 1(Long)
2025-08-19 09:59:15.313 DEBUG  [nio-8088-exec-1] com.demo.mapper.AccountStepRelationMapper.insert:135  : ==> Parameters: 1950354444940083202(Long), 1(Long), 2222(Long), 1(Long)
2025-08-19 09:59:15.473 DEBUG  [nio-8088-exec-1] com.demo.mapper.AccountStepRelationMapper.insert:135  : ==> Parameters: 1950354444940083203(Long), 1(Long), 3333(Long), 1(Long)
2025-08-19 09:59:15.630 DEBUG  [nio-8088-exec-1] com.demo.mapper.AccountStepRelationMapper.insert:135  : ==> Parameters: 1950354444940083204(Long), 1(Long), 4444(Long), 1(Long)
2025-08-19 09:59:15.820 DEBUG  [nio-8088-exec-1] com.demo.mapper.AccountStepRelationMapper.insert:135  : ==> Parameters: 1950354444940083205(Long), 1(Long), 5555(Long), 1(Long)
1950354444940083205
1950354444940083206
1950354444940083207
1950354444940083208
1950354444940083209
1950354444940083210
Mapper 插入的id尾号也是200~205。但是**model里面的id变了**