使用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版本。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM