243 Star 2.7K Fork 563

MyBatis-Flex/MyBatis-Flex

[Bug]: main方法直接调用updateChain方法构建一条sql语句后无法调用toSQL方法显示SQL语句

已完成
创建于  
2023-12-11 16:56

这个 Bug 是否已经存在:

如何复现:

public static void main(String[] args) {
    Environment environment = new Environment("mybatisFlex", new JdbcTransactionFactory(), new DelegatingDataSource());
    FlexConfiguration configuration = new FlexConfiguration(environment);
    FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
    globalConfig.setConfiguration(configuration);
    FlexGlobalConfig.setConfig("mybatisFlex", globalConfig, true);
    configuration.addMapper(AccountMapper.class);
    globalConfig.setDbType(DbType.MYSQL);

    IAccountServiceImpl service = new IAccountServiceImpl();
    AccountMapper baseMapper = Mappers.ofMapperClass(AccountMapper.class);
    Field field = ReflectUtil.getField(ServiceImpl.class, "mapper");
    ReflectUtil.setFieldValue(service, field, baseMapper);
    System.out.println(service.updateChain()
            .from(ACCOUNT)
            .set(Account::getAge, 18)
            .and(ACCOUNT.ID.ge(10)).toSQL());
}

预期结果:

正常输出构建的sql语句

实际结果:

java.lang.RuntimeException: Can not newInstance class: club.bigtian.study.domain.Account_$$_jvsta81_0
at com.mybatisflex.core.util.ClassUtil.newInstance(ClassUtil.java:168)
at com.mybatisflex.core.update.ModifyAttrsRecordProxyFactory.get(ModifyAttrsRecordProxyFactory.java:58)
at com.mybatisflex.core.util.UpdateEntity.of(UpdateEntity.java:35)
at com.mybatisflex.core.update.UpdateChain.createEntity(UpdateChain.java:84)
at com.mybatisflex.core.update.UpdateChain.(UpdateChain.java:68)
at com.mybatisflex.core.update.UpdateChain.create(UpdateChain.java:90)
at com.mybatisflex.core.service.IService.updateChain(IService.java:648)
at club.bigtian.study.service.impl.MybatisFlexSqlPreview.main(MybatisFlexSqlPreview.java:36)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "com.mybatisflex.core.update.UpdateWrapper.set(com.mybatisflex.core.util.LambdaGetter, Object, boolean)" because "this.entityWrapper" is null
at com.mybatisflex.core.update.UpdateChain.set(UpdateChain.java:107)
at com.mybatisflex.core.update.UpdateChain.set(UpdateChain.java:39)
at com.mybatisflex.core.update.PropertySetter.set(PropertySetter.java:123)
at club.bigtian.study.service.impl.MybatisFlexSqlPreview.main(MybatisFlexSqlPreview.java:38)
Disconnected from the target VM, address: '127.0.0.1:54054', transport: 'socket'

截图或视频:

输入图片说明

关联版本:

1.7.5

评论 (0)

时间淡忘一切 创建了任务 1年前
时间淡忘一切 添加了
 
bug
标签
1年前
时间淡忘一切 修改了描述 1年前
时间淡忘一切 修改了描述 1年前
时间淡忘一切 修改了描述 1年前
时间淡忘一切 修改了描述 1年前
Michael Yang 任务状态待办的 修改为已完成 1年前
展开全部操作日志

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(1)
2079235 djxchi 1662084101
1
https://gitee.com/mybatis-flex/mybatis-flex.git
git@gitee.com:mybatis-flex/mybatis-flex.git
mybatis-flex
mybatis-flex
MyBatis-Flex

搜索帮助