wangjing112 opened a new issue #4835: interface 
PreciseShardingAlgorithm.doSharding this param PreciseShardingValue type error
URL: https://github.com/apache/incubator-shardingsphere/issues/4835
 
 
   sharding-jdbc 4.0.0-RC2
   
   ### my own sharding def:
   `
   public class PreciseShardingTableAlgorithm implements 
PreciseShardingAlgorithm<Long> {
   
        @Override
        public String doSharding(Collection<String> availableTargetNames, 
PreciseShardingValue<Long> shardingValue) {
                String idx = (shardingValue.getValue() / 
ShardingCfg.DATABASE_SIZE) % ShardingCfg.TABLE_SIZE + "";
                for (String each : availableTargetNames) {
               if (each.endsWith(idx)) {
                   return each;
               }
           }
           throw new UnsupportedOperationException();
        }
   `
   
   ### but exec sql call shardingValue byte is PreciseShardingValue<Integer> 
lead to throw  ClassCastException
   
   ### btw:the table t_role_mail roleId type is Long
   
   ### error log:
   `
   Hibernate: select mailentity0_.id as id3_, mailentity0_.roleId as roleId3_, 
mailentity0_.acceptId as acceptId3_, mailentity0_.affix as affix3_, 
mailentity0_.affixStatus as affixSta5_3_, mailentity0_.affixType as 
affixType3_, mailentity0_.content as content3_, mailentity0_.contentType as 
contentT8_3_, mailentity0_.createTime as createTime3_, 
mailentity0_.durationSeconds as duratio10_3_, mailentity0_.ext as ext3_, 
mailentity0_.iconId as iconId3_, mailentity0_.sender as sender3_, 
mailentity0_.senderType as senderType3_, mailentity0_.status as status3_, 
mailentity0_.title as title3_, mailentity0_.type as type3_ from t_role_mail 
mailentity0_ where mailentity0_.roleId=0 or mailentity0_.roleId=1 limit ?
   2020-03-19 11:23:11.082  INFO 31054 --- [io-10000-exec-1] 
com.cg.raid.db.sharding.ShardingCfg      : DATABASE_SIZE :2
   2020-03-19 11:23:11.084  INFO 31054 --- [io-10000-exec-1] 
com.cg.raid.db.sharding.ShardingCfg      : DATABASE_SIZE :2,TABLE_SIZE:3
   三月 19, 2020 11:23:11 上午 org.apache.catalina.core.StandardWrapperValve invoke
   严重: Servlet.service() for servlet [dispatcherServlet] in context with path 
[] threw exception [Request processing failed; nested exception is 
com.cg.raid.core.orm.DataAccessException: java.lang.ClassCastException: 
java.lang.Integer cannot be cast to java.lang.Long] with root cause
   java.lang.ClassCastException: java.lang.Integer cannot be cast to 
java.lang.Long
        at 
com.cg.raid.db.sharding.PreciseShardingTableAlgorithm.doSharding(PreciseShardingTableAlgorithm.java:21)
        at 
org.apache.shardingsphere.core.strategy.route.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:79)
        at 
org.apache.shardingsphere.core.strategy.route.standard.StandardShardingStrategy.doSharding(StandardShardingStrategy.java:60)
        at 
org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine.routeTables(StandardRoutingEngine.java:211)
        at 
org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine.route(StandardRoutingEngine.java:193)
        at 
org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine.routeByShardingConditionsWithCondition(StandardRoutingEngine.java:120)
        at 
org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine.routeByShardingConditions(StandardRoutingEngine.java:114)
        at 
org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine.getDataNodes(StandardRoutingEngine.java:99)
        at 
org.apache.shardingsphere.core.route.type.standard.StandardRoutingEngine.route(StandardRoutingEngine.java:77)
        at 
org.apache.shardingsphere.core.route.router.sharding.ParsingSQLRouter.route(ParsingSQLRouter.java:93)
        at 
org.apache.shardingsphere.core.route.PreparedStatementRoutingEngine.route(PreparedStatementRoutingEngine.java:66)
        at 
org.apache.shardingsphere.core.PreparedQueryShardingEngine.route(PreparedQueryShardingEngine.java:60)
        at 
org.apache.shardingsphere.core.BaseShardingEngine.executeRoute(BaseShardingEngine.java:88)
        at 
org.apache.shardingsphere.core.BaseShardingEngine.shard(BaseShardingEngine.java:72)
        at 
org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.shard(ShardingPreparedStatement.java:220)
        at 
org.apache.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.executeQuery(ShardingPreparedStatement.java:108)
        at 
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1869)
        at org.hibernate.loader.Loader.doQuery(Loader.java:718)
        at 
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
        at org.hibernate.loader.Loader.doList(Loader.java:2449)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
        at org.hibernate.loader.Loader.list(Loader.java:2187)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
        at 
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
        at 
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   `

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to