apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
19.95k stars 6.74k forks source link

java.time.LocalDateTime cannot be cast to java.sql.Timestamp #14854

Closed xiaowu5759 closed 2 years ago

xiaowu5759 commented 2 years ago

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details. If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

shardingsphere-jdbc-core-spring-boot-starter 5.0.0 mysql-connector-java 8.0.26 mybatis 3.5.6

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC

Expected behavior

Actual behavior

column: gmt_create datetime not null comment '创建时间',

entity: private Date gmtCreate;

When I use mos order,mos order_ Item, if the binding table rule is adopted, there will be no problem and the correct results will be obtained, but there will be problems where the binding rule is not exist;

binding rule is exist binding-tables[0]: mos_order, mos_order_item

2022-01-18 14:00:22.830 |  INFO [mall-order,4a4bd6778c83e800,fa92744412fdcda6,true] | [http-nio-9502-exec-1] | ShardingSphere-SQL | log:74 | Logic SQL: SELECT mo.order_id, mo.order_no, mo.total_quantity, mo.total_amount, mo.order_context, mo.order_status, mo.remark, mo.user_id, mo.coupon_id, mo.coupon_amount, mo.freight_amount, mo.pay_amount, mo.pay_time, mo.pay_type, mo.delivery_time, mo.receive_time, mo.comment_time, mo.gmt_create, mo.gmt_modified, mo.tenant_code, mo.is_deleted, GROUP_CONCAT(moi.sku_id) AS sku_ids FROM mos_order AS mo LEFT JOIN mos_order_item AS moi ON mo.order_id = moi.order_id AND moi.tenant_code = '000000000' WHERE mo.is_deleted = 0 AND moi.is_deleted = 0 AND mo.order_id = ? AND mo.user_id = ? AND mo.tenant_code = '000000000' GROUP BY mo.order_id
2022-01-18 14:00:22.832 |  INFO [mall-order,4a4bd6778c83e800,fa92744412fdcda6,true] | [http-nio-9502-exec-1] | ShardingSphere-SQL | log:74 | SQLStatement: MySQLSelectStatement(limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2022-01-18 14:00:22.833 |  INFO [mall-order,4a4bd6778c83e800,fa92744412fdcda6,true] | [http-nio-9502-exec-1] | ShardingSphere-SQL | log:74 | Actual SQL: mos0 ::: SELECT mo.order_id, mo.order_no, mo.total_quantity, mo.total_amount, mo.order_context, mo.order_status, mo.remark, mo.user_id, mo.coupon_id, mo.coupon_amount, mo.freight_amount, mo.pay_amount, mo.pay_time, mo.pay_type, mo.delivery_time, mo.receive_time, mo.comment_time, mo.gmt_create, mo.gmt_modified, mo.tenant_code, mo.is_deleted, GROUP_CONCAT(moi.sku_id) AS sku_ids FROM mos_order1 AS mo LEFT JOIN mos_order_item1 AS moi ON mo.order_id = moi.order_id AND moi.tenant_code = '000000000' WHERE mo.is_deleted = 0 AND moi.is_deleted = 0 AND mo.order_id = ? AND mo.user_id = ? AND mo.tenant_code = '000000000' GROUP BY mo.order_id ::: [583349761680089089, 6879248199454720]
2022-01-18 14:00:22.881 |  WARN [mall-order,4a4bd6778c83e800,fa92744412fdcda6,true] | [http-nio-9502-exec-1] | com.alibaba.druid.pool.DruidAbstractDataSource | testConnectionInternal:1494 | discard long time none received connection. , jdbcUrl : jdbc:mysql://127.0.0.1:3306/mos0?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai, version : 1.2.5, lastPacketReceivedIdleMillis : 71638
<==    Columns: order_id, order_no, total_quantity, total_amount, order_context, order_status, remark, user_id, coupon_id, coupon_amount, freight_amount, pay_amount, pay_time, pay_type, delivery_time, receive_time, comment_time, gmt_create, gmt_modified, tenant_code, is_deleted, sku_ids
<==        Row: 583349761680089089, 20220118090347583349761680089088, 5, 5000, null, 101, null, 6879248199454720, 0, 0, 0, 0, null, null, null, null, null, 2022-01-18 09:03:47, 2022-01-18 09:03:47, 000000000, 0, <<BLOB>>
<==      Total: 1

binding rule is not exist

2022-01-18 14:03:01.214 |  INFO [mall-order,04b8f5b105527848,1b9e4c51e43868ad,true] | [http-nio-9502-exec-1] | ShardingSphere-SQL | log:74 | Logic SQL: SELECT mo.order_id, mo.order_no, mo.total_quantity, mo.total_amount, mo.order_context, mo.order_status, mo.remark, mo.user_id, mo.coupon_id, mo.coupon_amount, mo.freight_amount, mo.pay_amount, mo.pay_time, mo.pay_type, mo.delivery_time, mo.receive_time, mo.comment_time, mo.gmt_create, mo.gmt_modified, mo.tenant_code, mo.is_deleted, GROUP_CONCAT(moi.sku_id) AS sku_ids FROM mos_order AS mo LEFT JOIN mos_order_item AS moi ON mo.order_id = moi.order_id AND moi.tenant_code = '000000000' WHERE mo.is_deleted = 0 AND moi.is_deleted = 0 AND mo.order_id = ? AND mo.user_id = ? AND mo.tenant_code = '000000000' GROUP BY mo.order_id
2022-01-18 14:03:01.215 |  INFO [mall-order,04b8f5b105527848,1b9e4c51e43868ad,true] | [http-nio-9502-exec-1] | ShardingSphere-SQL | log:74 | SQLStatement: MySQLSelectStatement(limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2022-01-18 14:03:01.216 |  INFO [mall-order,04b8f5b105527848,1b9e4c51e43868ad,true] | [http-nio-9502-exec-1] | ShardingSphere-SQL | log:74 | Actual SQL: mos0 ::: SELECT mo.order_id, mo.order_no, mo.total_quantity, mo.total_amount, mo.order_context, mo.order_status, mo.remark, mo.user_id, mo.coupon_id, mo.coupon_amount, mo.freight_amount, mo.pay_amount, mo.pay_time, mo.pay_type, mo.delivery_time, mo.receive_time, mo.comment_time, mo.gmt_create, mo.gmt_modified, mo.tenant_code, mo.is_deleted, GROUP_CONCAT(moi.sku_id) AS sku_ids FROM mos_order1 AS mo LEFT JOIN mos_order_item0 AS moi ON mo.order_id = moi.order_id AND moi.tenant_code = '000000000' WHERE mo.is_deleted = 0 AND moi.is_deleted = 0 AND mo.order_id = ? AND mo.user_id = ? AND mo.tenant_code = '000000000' GROUP BY mo.order_id ORDER BY mo.order_id ASC  ::: [583349761680089089, 6879248199454720]
2022-01-18 14:03:01.216 |  INFO [mall-order,04b8f5b105527848,1b9e4c51e43868ad,true] | [http-nio-9502-exec-1] | ShardingSphere-SQL | log:74 | Actual SQL: mos0 ::: SELECT mo.order_id, mo.order_no, mo.total_quantity, mo.total_amount, mo.order_context, mo.order_status, mo.remark, mo.user_id, mo.coupon_id, mo.coupon_amount, mo.freight_amount, mo.pay_amount, mo.pay_time, mo.pay_type, mo.delivery_time, mo.receive_time, mo.comment_time, mo.gmt_create, mo.gmt_modified, mo.tenant_code, mo.is_deleted, GROUP_CONCAT(moi.sku_id) AS sku_ids FROM mos_order1 AS mo LEFT JOIN mos_order_item1 AS moi ON mo.order_id = moi.order_id AND moi.tenant_code = '000000000' WHERE mo.is_deleted = 0 AND moi.is_deleted = 0 AND mo.order_id = ? AND mo.user_id = ? AND mo.tenant_code = '000000000' GROUP BY mo.order_id ORDER BY mo.order_id ASC  ::: [583349761680089089, 6879248199454720]
<==    Columns: order_id, order_no, total_quantity, total_amount, order_context, order_status, remark, user_id, coupon_id, coupon_amount, freight_amount, pay_amount, pay_time, pay_type, delivery_time, receive_time, comment_time, gmt_create, gmt_modified, tenant_code, is_deleted, sku_ids
<==        Row: 583349761680089089, 20220118090347583349761680089088, 5, 5000, null, 101, null, 6879248199454720, 0, 0, 0, 0, null, null, null, null, null, 2022-01-18T09:03:47, 2022-01-18T09:03:47, 000000000, 0, <<BLOB>>

it is error

Caused by: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'gmt_create' from result set.  Cause: java.lang.ClassCastException: java.time.LocalDateTime cannot be cast to java.sql.Timestamp
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:87)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:511)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:480)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:404)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:354)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:328)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:301)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:194)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
    at com.sun.proxy.$Proxy351.query(Unknown Source)
    at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doQuery(MybatisSimpleExecutor.java:69)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
    at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.query(MybatisCachingExecutor.java:165)
    at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:81)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
    at com.sun.proxy.$Proxy350.query(Unknown Source)
    at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:111)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
    at com.sun.proxy.$Proxy350.query(Unknown Source)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
    ... 91 common frames omitted
Caused by: java.lang.ClassCastException: java.time.LocalDateTime cannot be cast to java.sql.Timestamp
    at org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet.getTimestamp(ShardingSphereResultSet.java:249)
    at org.apache.shardingsphere.driver.jdbc.core.resultset.ShardingSphereResultSet.getTimestamp(ShardingSphereResultSet.java:254)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.ibatis.logging.jdbc.ResultSetLogger.invoke(ResultSetLogger.java:69)
    at com.sun.proxy.$Proxy354.getTimestamp(Unknown Source)
    at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:39)
    at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:28)
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:85)
    ... 124 common frames omitted

My guess is that the date type of obtaining multiple result summaries is different from that of the original query

Reason analyze (If you can)

and mysql-connector-java 8.0.26 is error mysql-connector-java 8.0.19 is fine

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

RaigorJiang commented 2 years ago

What is your version of MySQL server?

xiaowu5759 commented 2 years ago

mysql version is 8.0.26

RaigorJiang commented 2 years ago

Maybe @strongduanmu can help us to check it.

strongduanmu commented 2 years ago

@xiaowu5759 Hi, can you try the master branch? I think this bug has been fixed.

xiaowu5759 commented 2 years ago

@xiaowu5759 Hi, can you try the master branch? I think this bug has been fixed.

I just used the latest version in Maven. ther master branch how to try

<dependency>
  <groupId>org.apache.shardingsphere</groupId>
  <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
  <version>5.0.0</version>
</dependency>
strongduanmu commented 2 years ago

@xiaowu5759 You can download here——http://117.48.121.24:8080/JDBC/.

terrymanu commented 2 years ago

Closed because of no response for long time.