JPA 复杂查询报错
“msg”: “Parameter value [PENDING] did not match expected type [com.iqiyi.mbd.qifang.reward.common.enums.RewardOrderStateEnum (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [PENDING] did not match expected type [com.iqiyi.mbd.qifang.reward.common.enums.RewardOrderStateEnum (n/a)]”,
使用了如下的查询语句
predicates.add(cb.notEqual(root.get(“paymentState”), RewardOrderStateEnum.PENDING.name()));
entity实体如下:
@Column(name = “payment_state”)
@Enumerated(EnumType.STRING)
private RewardOrderStateEnum paymentState;
具体原因:
Specification
root.get(“xxx”)得到的是实体中字段的引用类型,所以不能用字符串和枚举值相比对
解决方法:
改成如下语句
predicates.add(cb.notEqual(root.get(“paymentState”), RewardOrderStateEnum.PENDING));