使用LambdaQueryWrapper 报错MybatisPlusException: can not find lambda cache for this property [****]

【Exception】MybatisPlusException: can not find lambda cache for this entity Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity [fun.maso.entity.SubTableBaseEntity] 阅读详情
AI摘要

在使用Mockito进行MybatisPlus的Service层单元测试时,由于Mapper被mock,导致TableInfo无法初始化,进而引发Lambda查询异常。解决方案是在测试前手动调用TableInfoHelper.initTableInfo进行初始化。此问题的根本原因在于单元测试环境下,实体的TableInfo没有正常被缓存。

目录

背景

问题

分析

原因

解决方案

深层次原因


背景

        进行单元测试编码时,使用了MybatisPlus,在对service层进行单元测试时,为保证数据与应用隔离,采用Mock的方式.

问题

        Mockito对Mapper进行mock后,相关的TableInfo信息无法初始化,导致Wrapper组装条件时
报:com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property [****] of entity [Entity]

        我们在使用mybatisplus 时使用Lambda 表达式做查询条件会遇到mybatis拿不到缓存问题:
错误1:com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity
错误2:can not find lambda cache for this property [XXX] of entity [com.XXX.XXX]

分析

        排错时发现LambdaUtils.getColumnMap(aClass)中无数据;


原因

        首先是MybatisPlus的bug,经过分析后排除,再次考虑TableInfo的初始化过程被中止,或者被Mock替换了,更有可能是压根就没有触发。

        项目中使用JUnit & Mocktio进行单元测试,如果代码中使用LambdaQueryWrapper进行条件构造,在DO类中有类似@TableId、@TableLogic等注解,在执行单元测试时会报错 MybatisPlusException: can not find lambda cache for this property [] of entity []
问题:Mockito对Mapper进行mock后,相关的TableInfo信息无法初始化,导致Wrapper组装条件时
报:com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property [****] of entity [Entity]
 

解决方案

        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), “”), TeamWorkerSearch.class) 这一行就行,其中TeamWorkerSearch 是你要做条件的entity 对象

解决的方案是手动触发相关缓存信息收集(或许还有更优雅的方案)

在执行目标方法之前添加如下内容:

TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""),Xxx.class);

假如一个test类里面使用到的方法多的话,可以使用before注解让这行代码在测试类中所有方法执行之前就添加。在junit 5.x中,@Before主键被@BeforeEach所替代。

 @BeforeEach
    public void initTable() {
        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), Xxx.class);
    }

或者
 @Before
    public void init() {
        TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), Xxx.class);
    }

深层次原因

AbstractSqlInjector 会将所有 MapperBuilderAssistant 中的实体调用 initTableInfo

放到 TABLE_INFO_CACHE 这个map当中

 

 然后在使用 LambdaQueryWrapper 做查询条件拼接的时候

它又会从 TABLE_INFO_CACHE 这个map中取出来 

 

【异常】使用 MyBatis-Plus 分页提示异常MybatisPlusException: can‘t found IPage for args! 如果你使用的是 Spring Boot,通常这个配置是自动的,但你也可以在 application.yml 或 application.properties 文件中进行配置。这个错误是因为在使用Mybatis-Plus的分页插件时,没有找到对应的IPage对象,没有为查询方法提供正确的 IPage 参数。Mapper 接口方法签名不正确,可能在 Mapper 接口中定义了一个分页查询方法,但是没有按照 MyBatis-Plus 的要求来定义。分页查询方法应该接收一个 IPage 类型的参数。 阅读详情

相关推荐

【异常】Mybatis-Plus在处理分页查询时无法找到 IPage 类型的参数,提示MybatisPlusException: can‘t found IPage for args!

(3)检查 Mybatis Plus 配置:确保 Mybatis Plus 的分页插件已经正确配置,并且没有与其他配置冲突。(1)检查 Mapper 接口方法签名:确保 Mapper 接口中用于分页查询的方法签名正确,包含了 IPage 类型的参数。可能的原因是参数不正确,在调用 Mapper 方法时,可能没有正确传递 IPage 类型的参数,或者传递的参数类型不正确。可能的原因是没有正确配置分页插件,Mybatis Plus 的配置可能有误,导致框架无法正确解析分页参数。

奶爸的编程之路,也就一周冷个三天 1923

MybatisPlusExcepection: can not find lambda cache for this property [XX] for entity [xxx]

项目有用到mybatis-plus还是挺香的,但是遇到一个坑 com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property [dbName] of entity [] 意思是实体类enetity及其字段没有缓存或者说指定字段没有缓存 这个需要具体问题具体分析,得先找到在哪缓存的?什么时候缓存的? 问题和解决方案 我这里的问题是因为继承太多 正常是一个mapp

weixin_39660224的博客 1万+

C/C++关于VScode报错“终端将被任务重用,按任意键关闭”的解决方案

这其实不是一种报错,有这个提示的原因是本地端口是被共享的,所以必须关闭一个进程才能执行另一个,只需要对 tasks.json文件做一些修改即可。 报错时候 此时的tasks.json为: { "version": "2.0.0", "command": "g++", "args": ["-g","${file}","-o","${fileDirname}/${fileBasenameNoExtension}.exe"], // 编译命令参数 "problemMatche

Jerry Man的博客 6426

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: cannot find column‘s cache for

(2)执行模块不使用该Wrappers写法,在有该mapper.java文件的模块提供接口给执行模块使用。(1)在执行模块补充该文件。

qq_43639081的博客 3153

PDN设计

作者:AirCity 2020.2.6 Aircity007@sina.com 本文所有权归作者Aircity所有 PDN设计的目的是降低电源纹波水平,减小电压跌落。我们通常要求LDO的文波水平是30mV,DCDC是50mV,超过这个就需要PDN设计。 PDN设计的方法是用不同的容值,合适的总电容量,降低电源平面与地平面之间的交流阻抗,确定容值总量和电容大小的过程,就是PDN设计过程。 为什么需...

AirCity123的博客 4148

渗透测试之哥斯拉实战

可以直接在这里使用meterpreter命令进行对服务端的控制。选择目标 - 添加,配置连接信息,之后测试连接成功!php的shell功能如图。先要进行数据库的配置信息。可以直接在这里打包全站。

大河之犬的博客 2490

MybatisPlusException: can not find lambda cache for this entity[]异常解决

MybatisPlusException: can not find lambda cache for this entity[]异常解决

我的博客 4万+

ABAP CDS 视图参数 parameter_list 详解与最佳实践:从语法、作用域到可运行范例

本文系统梳理了ABAP CDS视图的WITH PARAMETERS定义与使用。主要内容包括:1)参数声明语法及其在整条SELECT语句中的贯穿使用;2)参数在WHERE/HAVING/ON等位置的多种写法(:pname和$parameters.pname);3)参数在航空公司航线筛选等实际业务场景中的应用;4)参数与会话变量的协作策略;5)在JOIN ON、HAVING、CASE等高级用法中的实践;6)提供完整的CDS视图与ABAP程序示例,展示参数声明、使用及Open SQL传参方式。所有内容均基于SAP

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 373

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: error: can not execute. because can n

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: error: can not execute. because can n

qq_46032178的博客 5928

【制作100个unity游戏之22】3DRPG游戏开发01——项目的设置和导入及渲染管线的安装修复

如果你现在存在一些疑惑unity导入素材为什么是粉紫色的?表示他没有适配我们的URP通用渲染管线,要如何适配呢?素材渲染错误丢失要如何解决?如果你有上面3个任意的问题,那这篇文章同样适合你,我将手把手教你如何安装修复渲染管线,看完你就了解了!在Unity中,他们都是渲染管线,它们的主要区别在于性能和功能。LWRP是早期版本的URP,它专门为移动设备和低端PC设计,旨在提供更高的性能。它使用基于顶点的光照和简化的后处理效果,可以在更低的硬件要求下运行。

向宇的博客,专注php/web全栈 unity游戏开发,欢迎大家评论纠错 2429

【深度学习|学习笔记】广义线性模型Generalized linear model(GLM)模型详解,附代码。

【深度学习|学习笔记】广义线性模型Generalized linear model(GLM)模型详解,附代码。

2401_89898861的博客 1877

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can‘t found IPage for args!

在自己写的mapper,xml但,又需要分页时,没有把page对象传入到mapper中。且要把这个page放到第一个参数。

10年老码农 1万+

「UG/NX」BlockUI 控件集合目录大纲

Block UI Styler 模块设计对话框是官方推荐使用的对话框制作方法,它能够与NX自身风格相统一,在实际开发中经常使用。文字内容包含:NX所有控件介绍的链接、内部控件调用的基础介绍、官方案例查看路径、控件的特殊用法篇链接、番外篇链接。

何曾参静谧的博客 2676

springboot 集成mybatis-plus异常 MybatisPlusException: can not find lambda cache for this property [*]

当前mybatis-plus 版本为3.3.2 <!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter 移除了mysql性能分析插件--> <dependency> <groupId>com.baomidou</groupId> <artifactId>myba

sinat_34338162的博客 1万+

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

mybatisplus.core.exceptions.MybatisPlusException: cannot find column’s cache for XX.实体

问题: Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: cannot find column’s cache for XXX.Manager$MMM_jr_57F235570CDF76AC_2, so you cannot used class com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper! 解决: 项目中使用的是: &

m0_47360218的博客 3380

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

can not find lambda cache for this property [XXX] of entity [com.XXX.XXX]

我们在使用mybatisplus 时使用Lambda 表达式做查询条件会遇到mybatis拿不到缓存问题: 错误1:com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity 错误2:can not find lambda cache for this property [XXX] of entity [com.XXX.XXX] @Override p

qq_36491545的博客 2万+

can not find lambda cache for this property [name] of entity [xxx.xxx.xxx.TbUser]

不能对标注有@TableField(exist = false)的属性字段进行条件查询,把name属性上面的@TableField(exist = false)注解去掉即可。查看TbUser这个实体类,发现name字段加上了@TableField(exist = false)注解,表示当前属性不是数据库的字段。不能在lambda缓存中找到某个实体类中的name字段;

puyan_100的博客 3197

Mockito +mybatis-plus遇到的问题

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity 只找到一个有点联系的解释 https://bbs.youkuaiyun.com/topics/395645965 没解决问题

sinat_25052547的博客 4845

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, please exclude the

使用mybatis plus写xml时候如果发现sql正确,在数据库中也能运行 可能是sql中有""的问题,可能框架底层动态拼接了sql外层加了"",所以xml中尽量要用' '

m0_37817220的博客 4万+

【Java异常】com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not use this method fo

本文目录 一、问题描述 二、问题原因 三、解决方案 项目背景描述:spring-boot (2.1.5) + mybatis-plus (3.3.1) + jdk8 一、问题描述 错误信息如下: Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew != null ...

No8g攻城狮的博客 4万+

记一篇Mockito MyBatisPlus 单元测试时报can not find lambda cache问题

记一篇Mockito MyBatisPlus 单元测试 junit 刚才在写单测时,由于代码中用到了queryWrapper.orderByDesc()方法,报错com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity [com.orm.mybatis.entity.Stusent] ...

weixin_43969830的博客 8511

MybatisPlusException: error: can not execute. because can not find column for id from entity

问题 使用mybatis-plus时 ,使用了方法saveOrUpdate,出现问题 com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: error: can not execute. because can not find column for id from entity! 解决 可以看到: can not find column for id from entity! 所以,需要对实体类 的主键 添加注解 @Tabl

Marcuslu的博客 7700

MybatisPlus实现分页效果并解决错误:cant found IPage for args!

早就知道MybatisPlus对分页进行了处理,但是一直没有实战用过,用的是自己封装的一个分页组件,虽不说麻烦吧,但是也不是特别简单。写起来还是比较复杂,但是最近这个组件有了点小小的bug,我决定是时候放弃它了,毅然加入光荣的进化。然后我就去摸索使用MybatisPlus封装的分页组件,不用不知道,一用吓一跳。不得不说是真香啊!功能强大且使用简单吹了这么多,下面就简单下如何使用MybatisPlus实现分页效果使用起来简单且强大,真香!

见证自己学习,成长的记录 1万+

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException:

com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Failed to process, please exclude the tableName or statementId.

zznn0306的博客 5485
上一篇: Pod 的 phase 和 conditions 的区别
下一篇: Git Tag 打标签
RichardGeek
博客等级 码龄9年 139粉丝 286原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值