Closed Ryoui closed 11 months ago
问题在 insertSelective
接口:
@Override
@Lang(Caching.class)
//@SelectKey(statement = "SELECT SEQ.NEXTVAL FROM DUAL", keyProperty = "id", before = true, resultType = long.class)
@Options(useGeneratedKeys = true, keyProperty = "id")
@InsertProvider(type = EntityProvider.class, method = "insertSelective")
int insertSelective(T entity);
这里指定的 @Options(useGeneratedKeys = true, keyProperty = "id")
,如果你用的是最新2.x版本,建议使用:
@Mapper
public interface BugTestMapper extends BaseMapper<BugTest,Long> {
}
并在实体类指定:
@Entity.Table(value = "bug_test", remark = "bug复现类")
public class BugTest implements Serializable {
private static final long serialVersionUID = -3906291302100871629L;
@Entity.Column(value = "u_id", id = true, useGeneratedKeys = true)
private Long uId;
最新版本中使用 useGeneratedKeys = true
时会自动根据当前字段设置 keyProperty
。
如果用的不是最新版本,可以如下改动:
@org.apache.ibatis.annotations.Mapper
public interface BugTestMapper extends Mapper<BugTest,Long> {
@Override
@Lang(Caching.class)
@Options(useGeneratedKeys = true, keyProperty = "uId")
@InsertProvider(type = EntityProvider.class, method = "insertSelective")
int insertSelective(BugTest entity);
}
可以加Q群交流:277256950
感谢,已解决。我是2.x,直接改用baseMapper即可,实体类没添加useGeneratedkeys,验证成功。
达梦数据,使用mapper.insertSelective(xx);是报错,经测试使用mybatis-plus+达梦是不会报错的,在io.mapper+mysql也不会报错。 实体类主键是:u_id。,虽然报错,但数据是插入了数据库的,以下是错误信息:
实体类:
mapper:
xml: