当前使用版本(必填,否则不予处理)
3.3.2
该问题是如何引起的?(确定最新版也有问题再提!!!)
在mockito中用mapper的mockbean会报↓ 3.1.0中可用 com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity
重现步骤(如果有就写完整)
在springboot做junit测试
报错信息
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity
Comment From: Cyankyo
上面这个问题在mockito方法执行前加 TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), xxxxDO.class);可以不产生。
但是多个mockitoTest 一起执行的时候会报 Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for xxx.xxxx.xxx.xxxxMapper.mybatis-plus_xxxxxDO
其中这个类有使用autoResultMap=true有关系吗?
Comment From: JohnNiang
-
推荐使用
@Spy注解或Mockito.spy(new xyz()),并提前打桩:doReturn(Collections.emptyList()).when(spyObject).list(any()); -
TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), xxxxDO.class);放到@BeforeClass或@BeforeAll注解的静态方法内。
Comment From: Cyankyo
还需要把加了autoResultMap=true 对应的mapper都做@MockBean,不然会报 Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for null.mybatis-plus_xxxDO
我用的SpyBean,用Spy会报java.lang.NullPointerException
Comment From: Cyankyo
但是如果不用mockito的普通单元测试也一起执行,这些方式在普通单元测试里不管用,还是会报Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for xxx.xxxx.xxx.xxxxMapper.mybatis-plus_xxxxxDO
Comment From: JohnNiang
我这边测试是通过了的,没有出现以上问题
Comment From: QinxiuW
你好,我这里也有相同的错误。 当前使用版本是 3.3.2.
1.报错信息为 “com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this entity ”。
2.报错条件: 当使用OrderBy并带有Condition的情况下。
如:goodsMapper.selectList(Wrappers.
尝试:
- 使用 @Spy 注释。对象为 xxxxxMapper (interface)
- 使用 @SpyBean 注释。 对象为 xxxxxMapper (interface)
- 在test前加入 TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), xxxxDO.class);
这里的 xxxxDO.class 为 MyBatisPlusConfig
问题: 1. 上面提供的关于 --> TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), xxxxDO.class); 放到 @BeforeClass 或 @BeforeAll 注解的静态方法内。 这里的 xxxxDO.class 指的是MybatisConfig吗?
Comment From: miemieYaho
用 lambdaWrapper 需要完整启动mp,或者 TableInfoHelper.initTableInfo(new MapperBuilderAssistant(new MybatisConfiguration(), ""), xxxxDO.class); 放到 @BeforeClass 或 @BeforeAll 注解的静态方法内,xxxxDO是你的entity