使用mybatis出现org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment cannot be cast to org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment

完整错误如下:
nested exception is org.apache.ibatis.executor.ExecutorException: Error preparing statement. Cause: java.lang.ClassCastException: org.apache.shardingsphere.sql.parser.sql.segment.dml.expr.simple.ParameterMarkerExpressionSegment cannot be cast to org.apache.shardingsphere.sql.parser.sql.segment.dml.column.ColumnSegment

经过排查发现是我的SQL有问题,SQL如下
SELECT
    bs.id,bs.sku_id,s.original_sku_name,s.interest_point,s.price,s.image_url,s.coupon_price,s.commission
FROM
    brand_sku bs
LEFT JOIN sku s ON bs.sku_id = s.sku_id
WHERE
    bs.brand_id = 1
AND now() BETWEEN s.coupon_use_begin_time AND s.coupon_use_end_time
AND s.meet_img_url != '' ORDER BY bs.top DESC;
在经过删除SQL中的代码测试后,发现其实原因是因为加粗的那段条件BETWEEN AND导致的,在我把SQL语句改成AND now() >= s.coupon_use_begin_time AND s.coupon_use_end_time >= now()之后就发现不再报错了。
所以,如果你也有此种错误,我建议你试试排查你的SQL是否存在问题,比如上面的将between and修改成>=。
解决方法2
事情的真实原因是sharding的版本问题,你也可以选择升级你的sharding版本。

posted @ 2020-12-07 20:03  诺言和岁月  阅读(10500)  评论(0)    收藏  举报