当前位置: 代码迷 >> 综合 >> mybatis中使用union出现Cannot convert string ‘WECHAT‘ to java.sql.Timestamp value
  详细解决方案

mybatis中使用union出现Cannot convert string ‘WECHAT‘ to java.sql.Timestamp value

热度:122   发布时间:2023-09-29 06:47:04.0

问题:

rg.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'create_time' from result set.  Cause: java.sql.SQLDataException: Cannot convert string 'WECHAT' to java.sql.Timestamp value
; ]; Cannot convert string 'WECHAT' to java.sql.Timestamp value; nested exception is java.sql.SQLDataException: Cannot convert string 'WECHAT' to java.sql.Timestamp value

原因:

我union前后的两个语句的字段排列不一致,导致转换成实体类出错。

(Select info.order_id,info.status,info.no,'1' as type,info.create_time,info.trade_type,from t_info info
)
union all(select refun.id,refun.status,refun.no,'2' as type,refun.trade_type,refunpay.create_time,
from t_refund_info refun)

连个select 语句的查询结果必须字段一致,顺序一致。

  相关解决方案