baomidou / mybatis-plus

An powerful enhanced toolkit of MyBatis for simplify development
https://baomidou.com
Apache License 2.0
16.28k stars 4.29k forks source link

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

Open redcarp666 opened 1 month ago

redcarp666 commented 1 month ago

确认

当前程序版本

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 commented 1 month ago

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

redcarp666 commented 1 month ago

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

@Mapper
public interface EmConversionCoefficientMapper extends BaseMapper<EmConversionCoefficient> {

}

@miemieYaho 有的

miemieYaho commented 1 month ago

那你Wrappers.lambdaQuery(EmConversionCoefficient.class)

redcarp666 commented 1 month ago

那你Wrappers.lambdaQuery(EmConversionCoefficient.class)

nieqiurong commented 3 weeks ago

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