当前使用版本(必填,否则不予处理)
3.4.3.4 / 3.4.3.3
该问题是如何引起的?(确定最新版也有问题再提!!!)
- 使用 逻辑删除 特性
- mapper.deleteById(entity) 触发更新会设置所有值(包括 NULL ), 和逻辑删除设置 DELETED_AT 冲突导致出现 Duplicate column name "DELETED_AT"; 异常
重现步骤(如果有就写完整)
ModelEntity entity = new ModelEntity();
mapper.insert(entity);
assertEquals(mapper.deleteById(entity), 1);
错误位置: com/baomidou/mybatis-plus-core/3.4.3.3/mybatis-plus-core-3.4.3.3-sources.jar!/com/baomidou/mybatisplus/core/injector/methods/DeleteById.java:52
报错信息
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Duplicate column name "DELETED_AT"; SQL statement:
UPDATE model_entity SET
last_updated_at=?,last_updater=?,deleted_at=?,deleter=?,
deleted_at=NOW(6) WHERE id=? AND deleted_at IS NULL [42121-200]
### The error may exist in in/hocg/boot/web/sample/logicdel/ModelEntityMapper.java (best guess)
### The error may involve in.hocg.boot.web.sample.logicdel.ModelEntityMapper.deleteById
### The error occurred while executing an update
### SQL: UPDATE model_entity SET last_updated_at=?,last_updater=?,deleted_at=?,deleter=?, deleted_at=NOW(6) WHERE id=? AND deleted_at IS NULL
### Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Duplicate column name "DELETED_AT"; SQL statement:
UPDATE model_entity SET
last_updated_at=?,last_updater=?,deleted_at=?,deleter=?,
deleted_at=NOW(6) WHERE id=? AND deleted_at IS NULL [42121-200]
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:196)
at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:64)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
Comment From: miemieYaho
给出完整demo
Comment From: nieqiurong
这种看着是在逻辑删除字段上指定了字段填充策略导致的