当前使用版本(必填,否则不予处理)
3.1.1
该问题是如何引起的?(确定最新版也有问题再提!!!)
自定义了个AbstractFissionParticipationServiceImpl抽象父类,继承ServiceImpl
public abstract class AbstractFissionParticipationServiceImpl
重现步骤(如果有就写完整)
抽象父类定义
public abstract class AbstractFissionParticipationServiceImpl
public int test(Long id) {
return count(Wrappers.<T>lambdaQuery()
.eq(T::getRoleType, MarketingConstants.LAUNCHER));
}
} 子类定义 此处getOne查询正常,调用test方法报错
public class FissionCouponParticipationServiceImpl extends AbstractFissionParticipationServiceImpl
public int test(Long id) {
FissionCouponParticipation participation = this.getOne(Wrappers.<FissionCouponParticipation>lambdaQuery()
.eq(FissionCouponParticipation::getRoleType, 2), false);
int cnt = this.test(22L);
}
抽象父实体类
public abstract class AbstractFissionParticipation extends Model
子实体类 @Data @TableName("fission_coupon_participation") @EqualsAndHashCode(callSuper = true) public class FissionCouponParticipation extends AbstractFissionParticipation { }
报错信息
最新3.3.2版本 MybatisPlusException: can not find lambda cache for this entity [com.xxx.entity.AbstractFissionParticipation]]
3.1.1版本 MybatisPlusException: Your property named "roleType" cannot find the corresponding database column name!]
第一次用这个,不知道怎么贴图。格式有点乱,麻烦解答下。多谢
Comment From: miemieYaho
不认范型,你可以setentityclass来定位缓存
Comment From: JoeyBling
不能通过set方法来进行设置,必须通过Wrapper的构造函数
return super.list(Wrappers.<T>lambdaQuery(entity).eq(T::getEnabled, true));
/**
* 基础实体类公用Service
*
* @author Created by 思伟 on 2020/8/24
* @see BaseEntity
*/
public abstract class SimpleService<S, M extends BaseMapper<T>, T extends BaseEntity> extends BaseAopService<S, M, T> {
/**
* 解决子类调用父类字段进行构造查询等问题
*
* @url { https://github.com/baomidou/mybatis-plus/issues/1935 }
* @url { https://github.com/baomidou/mybatis-plus/issues/2616 }
* @see AbstractLambdaWrapper#initNeed()
*/
private T entity;
public void setEntity(T entity) {
this.entity = entity;
}
public SimpleService() {
Class clazz = getClass();
try {
// 处理有继承的情况,有继承时,取父类(ParameterizedType = 泛型实例)
while (!ParameterizedType.class.isAssignableFrom(clazz.getGenericSuperclass().getClass())
&& !clazz.equals(Object.class)) {
clazz = clazz.getSuperclass();
}
// 取出第3个参数的实际类型(实体类对象类型)
Class<T> entityClass = (Class<T>) ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments()[2];
entity = entityClass.newInstance();
} catch (Throwable e) {
logger.error("{}注入entity失败,请手动重写`setEntity()`方法,e={}", clazz, e.getMessage());
}
}
/**
* 查询全部有效的数据
*
* @return List
*/
public List<T> listEnabledAll() {
return super.list(Wrappers.<T>lambdaQuery(entity)
.eq(T::getEnabled, true));
}
}