(bug记录)Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Arrays$ArrayList and java.lang.String
报错样式
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Arrays$ArrayList and java.lang.String
Cause: java.lang.IllegalArgumentException: invalid comparison: java.util.Arrays$ArrayList and java.lang.String
DAO(Mapper)层代码
List<String>queryRenewalAnnualCycles(@Param("renewalStrategyConfigVO")RenewalStrategyConfigVO renewalStrategyConfigVO,
@Param("policyStatusList")List<String> policyStatusList,
@Param("templateList")List<String> templateList);
mapper.xml代码
<select id="queryRenewalAnnualCycles" resultType="java.lang.String">
select distinct renewal_annual_cycles
from online_policy_insure_info a
where a.is_deleted != 'N'
and a.renewal_annual_cycles IS NOT NULL
and a.renewal_annual_cycles != ''
<if test="renewalStrategyConfigVO.goodsCode!=null and renewalStrategyConfigVO.goodsCode!=''">
and a.plan_code in
(select product_code
from cms_goods_product
where goods_code = #{renewalStrategyConfigVO.goodsCode})
</if>
<if test="renewalStrategyConfigVO.insurerCode!=null and renewalStrategyConfigVO.insurerCode!=''">
and a.insurer_code = #{renewalStrategyConfigVO.insurerCode}
</if>
<if test="policyStatusList!=null and policyStatusList!= ''">
and a.policy_status in
<foreach collection="policyStatusList" item="policyStatus" open="(" close=")" separator=",">
#{policyStatus}
</foreach>
</if>
<if test="templateList!=null and templateList!= ''">
and a.id in (select e.policy_id
from online_policy_pay_sign e
inner join cashier_template_config f on e.sign_template_code = f.template_code
inner join cashier_merchant_config g on f.merchant_code = g.merchant_code
where g.owner in
<foreach collection="templateList" item="template" open="(" close=")" separator=",">
#{template}
</foreach>)
</if>
</select>
报错解释
这个错误意味着在MyBatis执行数据库查询时出现了问题,导致无法正确比较某些值。错误提示指出了比较无效的对象类型,即"java.util.Arrays$ArrayList"和"java.lang.String"。
这通常意味着在MyBatis的SQL语句中,出现了对不同类型的数据进行比较的情况。比如,可能在WHERE子句或JOIN条件中,试图比较一个ArrayList类型的值和一个String类型的值,这是不允许的。
通过比对mapper代码和xml代码可以看到,我们在
and policyStatusList!= ''
and templateList!= ''
而这两个条件这就是造成报错的根源所在......(原本想添加的限制是集合不为null且不为空,习惯性按照字符串判空值的写法来写list类型,造成了bug)
解决方案
-
条件去除 != ''
-
改成 and templateList.size() > 0、and templateList.size() > 0即可