Please answer these questions before submitting your issue. Thanks!
Which version of Sharding-Jdbc do you using?
2.0.0.M2
Expected behavior
SQL加上id应该正常
Actual behavior
报错:Caused by: io.shardingjdbc.core.exception.ShardingJdbcException: Parameter null should extends Comparable for sharding value.
Steps to reproduce the behavior
使用mybatis:
1、SQL
INSERT INTO traffic (
id, name, createTime
)
VALUES (
#{id,jdbcType=BIGINT},
#{name,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}
)
2、配置
public String doSharding(final Collection availableTargetNames, final PreciseShardingValue shardingValue) {
for (String each : availableTargetNames) {
if (each.endsWith(shardingValue.getValue() % 2 + "")) {
return each;
}
}
throw new UnsupportedOperationException();
}
3、运行
Error updating database. Cause: io.shardingjdbc.core.exception.ShardingJdbcException: Parameter null should extends Comparable for sharding value.
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: INSERT INTO traffic ( id, name, createTime ) VALUES ( ?, ?, ? )
Cause: io.shardingjdbc.core.exception.ShardingJdbcException: Parameter null should extends Comparable for sharding value.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:200)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
... 7 more
Caused by: io.shardingjdbc.core.exception.ShardingJdbcException: Parameter null should extends Comparable for sharding value.
at io.shardingjdbc.core.parsing.parser.context.condition.Condition.getValues(Condition.java:100)
at io.shardingjdbc.core.parsing.parser.context.condition.Condition.getShardingValue(Condition.java:83)
at io.shardingjdbc.core.routing.type.simple.SimpleRoutingEngine.getShardingValues(SimpleRoutingEngine.java:108)
at io.shardingjdbc.core.routing.type.simple.SimpleRoutingEngine.getTableShardingValues(SimpleRoutingEngine.java:78)
at io.shardingjdbc.core.routing.type.simple.SimpleRoutingEngine.route(SimpleRoutingEngine.java:62)
at io.shardingjdbc.core.routing.router.ParsingSQLRouter.route(ParsingSQLRouter.java:120)
at io.shardingjdbc.core.routing.router.ParsingSQLRouter.route(ParsingSQLRouter.java:85)
at io.shardingjdbc.core.routing.PreparedStatementRoutingEngine.route(PreparedStatementRoutingEngine.java:57)
at io.shardingjdbc.core.jdbc.core.statement.ShardingPreparedStatement.route(ShardingPreparedStatement.java:150)
at io.shardingjdbc.core.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:140)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
... 13 more
Please provide the reproduce example codes (such as github link) if possible.