Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[错误报告]: 使用LambdaQueryWrapper中出现can not find lambda cache for this property #6400

Open
2 of 3 tasks
redcarp666 opened this issue Aug 13, 2024 · 5 comments
Open
2 of 3 tasks

Comments

@redcarp666
Copy link

redcarp666 commented Aug 13, 2024

确认

  • 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

当前程序版本

3.5.1

问题描述

代码如下, Entity是有effectiveStartTime的

public class EmConversionCoefficient extends BaseEntity {
	@ApiModelProperty(value = "名称")
	private String name;
	@ApiModelProperty(value = "生效开始月份")
	@JsonFormat(pattern = "yyyy-MM")
	private String effectiveStartTime;
	@ApiModelProperty(value = "生效结束月份")
	@JsonFormat(pattern = "yyyy-MM")
	private String effectiveEndTime;
	@ApiModelProperty(value = "组织ids(以英文逗号间隔)")
	private String refOrgIds;
	@ApiModelProperty(value = "备注")
	private String remark;
	@ApiModelProperty(value = "是否删除")
	@TableLogic
	@TableField(fill = FieldFill.INSERT)
	private Integer deleted = 0;
}
private LambdaQueryWrapper<EmConversionCoefficient> getQueryWrapper(EmConversionCoefficientVo.EmConversionCoefficientPageListInput input) {
		LambdaQueryWrapper<EmConversionCoefficient> wrapper = getBaseWrapper(input);
		wrapper.like(StringUtils.isNotEmpty(input.getName()),
		             EmConversionCoefficient::getName,
		             IbfStringUtil.replaceSpecialCharOfLike(input.getName()));
		wrapper.le(null != input.getEffectiveEndTime(),
		           EmConversionCoefficient::getEffectiveStartTime,
		           input.getEffectiveEndTime());
		wrapper.ge(null != input.getEffectiveStartTime(),
		           EmConversionCoefficient::getEffectiveEndTime,
		           input.getEffectiveStartTime());
		return wrapper;
	}
default <Input extends BaseQueryInput> LambdaQueryWrapper<T> getBaseWrapper(Input input) {
        LambdaQueryWrapper<T> wrapper = Wrappers.lambdaQuery();
	    wrapper.like(ObjectUtil.isNotEmpty(input.getCreator()), BaseEntity::getCreator, input.getCreator()).like(
			    ObjectUtil.isNotEmpty(input.getModifier()),
			    BaseEntity::getModifier,
			    input.getModifier());
	    wrapper.between(ObjectUtil.isNotEmpty(input.getCreateStartTime()) && ObjectUtil.isNotEmpty(input.getCreateEndTime()),
	                    BaseEntity::getCreateTime,
	                    input.getCreateStartTime(),
	                    EmDateUtil.endOfDay(input.getCreateEndTime()));
	    wrapper.between(ObjectUtil.isNotEmpty(input.getModifyStartTime()) && ObjectUtil.isNotEmpty(input.getModifyEndTime()),
	                    BaseEntity::getModifyTime,
	                    input.getModifyStartTime(),
	                    EmDateUtil.endOfDay(input.getModifyEndTime()));
        return wrapper;
    }

详细堆栈日志

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegment != null and ew.sqlSegment != '' and ew.nonEmptyOfNormal'. Cause: org.apache.ibatis.ognl.OgnlException: sqlSegment [com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: can not find lambda cache for this property [effectiveStartTime] of entity [cn.zjky.ibf.em.bim.entity.EmConversionCoefficient]]
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
	at com.sun.proxy.$Proxy144.selectList(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForIPage(MybatisMapperMethod.java:121)
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:85)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148)
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89)
	at com.sun.proxy.$Proxy172.selectPage(Unknown Source)
	at com.baomidou.mybatisplus.extension.service.IService.page(IService.java:389)
@miemieYaho
Copy link
Member

你有basemapper< EmConversionCoefficient >并且被正确加载了吗?

@redcarp666
Copy link
Author

redcarp666 commented Aug 13, 2024

你有basemapper< EmConversionCoefficient >并且被正确加载了吗?

@Mapper
public interface EmConversionCoefficientMapper extends BaseMapper<EmConversionCoefficient> {

}

@miemieYaho 有的

@miemieYaho
Copy link
Member

那你Wrappers.lambdaQuery(EmConversionCoefficient.class)

@redcarp666
Copy link
Author

那你Wrappers.lambdaQuery(EmConversionCoefficient.class)

  • 这样是可以,那就是得传LambdaQueryWrapper参数进去了。

  • image
  • 使用时,必须在后面拼接上公共条件的字段才不会报错。

  • image

@nieqiurong
Copy link
Contributor

也可以改成一下传入子类类型创建或者通过父类初始化的QueryWrapper后回来在setEntityClass一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants