You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/31 05:52:02 UTC

[GitHub] [shardingsphere] zhuhongxu opened a new issue #7167: bad constructor use

zhuhongxu opened a new issue #7167:
URL: https://github.com/apache/shardingsphere/issues/7167


   ## Bug Report
   
   **For English only**, other languages will not accept.
   
   Before report a bug, make sure you have:
   
   - Searched open and closed [GitHub issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   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?
   4.0.1
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   ### Expected behavior
   select a list by mybatis
   ### Actual behavior
   gives me an error:  java.sql.SQLException: Value '0' can not be represented as java.sql.Timestamp
   ### Reason analyze (If you can)
   the sql can be selected correctly in mysql-workbench, but can't work in my application, the reason probably is when constructed the list<A> from resultSet, sharding-jdbc use the A constructor signature and then foreach the field in it to choose a typeHanlder, but the field order in my constructor signature is not suit my sql, the method is org.apache.ibatis.executor.resultset.DefaultResultSetHandler#createByConstructorSignature
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   this table don't have sharding rule, just a common table.
   ### Example codes for reproduce this issue (such as a github link).
   <resultMap id="BaseResultMap" type="A">
       <id column="id" jdbcType="BIGINT" property="id" />
       <result column="letter_content" jdbcType="VARCHAR" property="letterContent" />
       <result column="message_id" jdbcType="VARCHAR" property="messageId" />
       <result column="num" jdbcType="INTEGER" property="num" />
       <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
     </resultMap>
   
   <select id="selectByMessageId" parameterType="java.lang.String" resultMap="BaseResultMap">
       select
       <include refid="Base_Column_List" />
       from A
       where message_id = #{messageId}
     </select>
   
   public class A {
       private Long id;
       private String letterContent;
       private String messageId;
       private Integer num;
       private Date createDate;
   
       public A(String letterContent, String messageId, Integer num, Date createDate) {
           this.letterContent = letterContent;
           this.messageId = messageId;
           this.num = num;
           this.createDate = createDate;
       }
   
       # don't have no arguments constructor.
   
   }
   
   shading-jdbc thinks the id column is string, letter_content is string, message_id is integer, and the num column is TIMESTAMP jdbcType,  and shading-jdbc thinks the num column should use DateTypeHandler to extract the actual value from resultSet,  but the num column value in mysql server is 0, so it gives a error:
   Caused by: java.sql.SQLException: Value '0' can not be represented as java.sql.Timestamp
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.mysql.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:947) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.mysql.jdbc.ByteArrayRow.getTimestampFast(ByteArrayRow.java:130) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.mysql.jdbc.ResultSetImpl.getTimestampInternal(ResultSetImpl.java:5921) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:5589) ~[mysql-connector-java-5.1.47.jar:5.1.47]
   	at com.alibaba.druid.pool.DruidPooledResultSet.getTimestamp(DruidPooledResultSet.java:220) ~[druid-1.1.10.jar:1.1.10]
   	at org.apache.shardingsphere.core.execute.sql.execute.result.StreamQueryResult.getValue(StreamQueryResult.java:84) ~[sharding-core-execute-4.0.1.jar:4.0.1]
   	at org.apache.shardingsphere.underlying.merge.impl.StreamMergedResult.getValue(StreamMergedResult.java:49) ~[shardingsphere-merge-4.0.1.jar:4.0.1]
   	at org.apache.shardingsphere.encrypt.merge.dql.EncryptMergedResult.getValue(EncryptMergedResult.java:50) ~[encrypt-core-merge-4.0.1.jar:4.0.1]
   	at org.apache.shardingsphere.shardingjdbc.jdbc.core.resultset.ShardingResultSet.getTimestamp(ShardingResultSet.java:254) ~[sharding-jdbc-core-4.0.1.jar:4.0.1]
   	at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:39) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.type.DateTypeHandler.getNullableResult(DateTypeHandler.java:28) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:81) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createUsingConstructor(DefaultResultSetHandler.java:671) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createByConstructorSignature(DefaultResultSetHandler.java:654) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:618) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.createResultObject(DefaultResultSetHandler.java:591) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:397) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:354) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:328) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:301) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:194) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:65) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:79) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:63) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) ~[mybatis-3.5.3.jar:3.5.3]
   	at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:108) ~[pagehelper-5.1.10.jar:?]
   	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.3.jar:3.5.3]
   	at com.sun.proxy.$Proxy122.query(Unknown Source) ~[?:?]
   	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.3.jar:3.5.3]
   	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.3.jar:3.5.3]
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_221]
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_221]
   	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_221]
   	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426) ~[mybatis-spring-2.0.3.jar:2.0.3]
   
   
   
   if I add a no arguments constructor, the problem will be solved, but when using mybatis only, there don't have this problem.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] zhuhongxu commented on issue #7167: bad constructor use

Posted by GitBox <gi...@apache.org>.
zhuhongxu commented on issue #7167:
URL: https://github.com/apache/shardingsphere/issues/7167#issuecomment-683571530


   it is my problem


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] zhuhongxu closed issue #7167: bad constructor use

Posted by GitBox <gi...@apache.org>.
zhuhongxu closed issue #7167:
URL: https://github.com/apache/shardingsphere/issues/7167


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org