错误信息如下:
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity com.copm.ifm.base.basic.pojo.BaseTreePO
// 或者
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property treeNo of entity com.copm.ifm.base.basic.pojo.BaseTreePO
因为MybatisPlus3.2+之后不会缓存实体类的父类字段信息,所以在使用父类的Lambda表达式时会报错.
具体是在执行com.baomidou.mybatisplus.core.toolkit.LambdaUtils#getColumnMap(Class)
时,MybatisPlus会将Mapper中的实体类(即BaseMapper<Class>
的Class)字段信息,缓存到com.baomidou.mybatisplus.core.toolkit.LambdaUtils
的COLUMN_CACHE_MAP
中。
但是MybatisPlus3.2+之后不会加载父类的信息了,所以COLUMN_CACHE_MAP
中没有相关缓存,于是报错了。
因此解决方案是, 手动将BaseTreePO
添加到缓存中。代码如下:
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), BaseTreePO.class) ;
网友评论