You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "changanluan (via GitHub)" <gi...@apache.org> on 2023/03/04 14:43:16 UTC

[GitHub] [shardingsphere] changanluan opened a new issue, #24460: SQLServer 2012 page query java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

changanluan opened a new issue, #24460:
URL: https://github.com/apache/shardingsphere/issues/24460

   ## Bug Report
   
   I use   @PersistenceContext  private EntityManager entityManager to execute a paged query in SqlServer 2012, the sql :
   Hibernate: select wfconsumer0_.WC029_GUID as col_0_0_ from WF029_CONSUMEELOG wfconsumer0_ where 1=1 and wfconsumer0_.WC029_STATE=1 order by col_11_0_ desc offset ? rows fetch next ? rows only
   
   
   
   
   ### Which version of ShardingSphere did you use?
   5.3.1
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   ### Expected behavior
   
   ### Actual behavior
         javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
   	at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154) ~[hibernate-core-5.6.15.Final.jar:5.6.15.Final]
   	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1626) ~[hibernate-core-5.6.15.Final.jar:5.6.15.Final]
   	at org.hibernate.query.Query.getResultList(Query.java:165) ~[hibernate-core-5.6.15.Final.jar:5.6.15.Final]
   Caused by: java.sql.SQLException: Unknown exception: Index: 2, Size: 2
   	at org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException.toSQLException(ShardingSphereSQLException.java:62) ~[shardingsphere-infra-util-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.dialect.SQLExceptionTransformEngine.toSQLException(SQLExceptionTransformEngine.java:62) ~[shardingsphere-dialect-exception-core-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeQuery(ShardingSpherePreparedStatement.java:249) ~[shardingsphere-jdbc-core-5.3.1.jar:5.3.1]
   	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57) ~[hibernate-core-5.6.15.Final.jar:5.6.15.Final]
   	... 116 common frames omitted
   Caused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
   	at java.util.ArrayList.rangeCheck(ArrayList.java:659) ~[na:1.8.0_271]
   	at java.util.ArrayList.get(ArrayList.java:435) ~[na:1.8.0_271]
   	at org.apache.shardingsphere.infra.binder.segment.select.pagination.PaginationContext.getValue(PaginationContext.java:56) ~[shardingsphere-infra-binder-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.infra.binder.segment.select.pagination.PaginationContext.<init>(PaginationContext.java:51) ~[shardingsphere-infra-binder-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.infra.binder.segment.select.pagination.engine.LimitPaginationContextEngine.createPaginationContext(LimitPaginationContextEngine.java:38) ~[shardingsphere-infra-binder-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.infra.binder.segment.select.pagination.engine.PaginationContextEngine.createPaginationContext(PaginationContextEngine.java:57) ~[shardingsphere-infra-binder-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext.setUpParameters(SelectStatementContext.java:336) ~[shardingsphere-infra-binder-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createQueryContext(ShardingSpherePreparedStatement.java:565) ~[shardingsphere-jdbc-core-5.3.1.jar:5.3.1]
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeQuery(ShardingSpherePreparedStatement.java:228) ~[shardingsphere-jdbc-core-5.3.1.jar:5.3.1]
   	... 117 common frames omitted
   
   2023-03-04 22:37:41.294  INFO 27988 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
   
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
     @Primary
     @Bean
     public DataSource shardingDataSource() throws SQLException {
      
       Map<String, DataSource> dataSourceMap = new HashMap<>();
       dataSourceMap.put("master-ds", shardingMasterDataSourceProperties().initializeDataSourceBuilder().build());
       dataSourceMap.put("slave-ds1", shardingSlave1DataSourceProperties().initializeDataSourceBuilder().build());
   
       List<ReadwriteSplittingDataSourceRuleConfiguration> dsConfigurations = new ArrayList<>();
       Properties readwriteProps1 = new Properties();
       readwriteProps1.setProperty("write-data-source-name", "master-ds");
       readwriteProps1.setProperty("read-data-source-names", "slave-ds1");
       dsConfigurations.add(new ReadwriteSplittingDataSourceRuleConfiguration("ds", new StaticReadwriteSplittingStrategyConfiguration("master-ds",
         Arrays.asList("slave-ds1")), null,"load_balancer"));
       
       Map<String, AlgorithmConfiguration> loadBalancers = new HashMap<>();
       loadBalancers.put("load_balancer", new AlgorithmConfiguration("ROUND_ROBIN", new Properties()));
       ReadwriteSplittingRuleConfiguration ruleConfiguration = new ReadwriteSplittingRuleConfiguration(dsConfigurations, loadBalancers);
   
       return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Collections.singleton(ruleConfiguration), new Properties());
     }
   
         Query query = getWfLogPageQuery(criteria);
         query.unwrap(QueryImpl.class).setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
         query.setFirstResult(pageNumber * pageSize);
         query.setMaxResults(pageSize);
         contentList = query.getResultList();
   
   
   
   ### Example codes for reproduce this issue (such as a github link).
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

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


[GitHub] [shardingsphere] wjtien commented on issue #24460: SQLServer 2012 page query java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

Posted by "wjtien (via GitHub)" <gi...@apache.org>.
wjtien commented on issue #24460:
URL: https://github.com/apache/shardingsphere/issues/24460#issuecomment-1482460723

   https://shardingsphere.apache.org/document/current/cn/features/sharding/limitation/
   
   分页查询
   Oracle 和 SQLServer 由于分页查询较为复杂,目前有部分分页查询不支持,具体如下:
   
   Oracle
   目前不支持 rownum + BETWEEN 的分页方式。
   
   SQLServer
   目前不支持使用 WITH xxx AS (SELECT …) 的方式进行分页。由于 Hibernate 自动生成的 SQLServer 分页语句使用了 WITH 语句,因此目前并不支持基于 Hibernate 的 SQLServer 分页。 目前也不支持使用两个 TOP + 子查询的方式实现分页。
   
   不知道是不是,但是你也没有with啊。。


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] azexcy commented on issue #24460: SQLServer 2012 page query java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on issue #24460:
URL: https://github.com/apache/shardingsphere/issues/24460#issuecomment-1458096144

   Hi @tuichenchuxin , can you help me to look at this


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] tuichenchuxin commented on issue #24460: SQLServer 2012 page query java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

Posted by "tuichenchuxin (via GitHub)" <gi...@apache.org>.
tuichenchuxin commented on issue #24460:
URL: https://github.com/apache/shardingsphere/issues/24460#issuecomment-1461100564

   This looks like it's due to not parsing the parameter for "fetch next ?".


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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


[GitHub] [shardingsphere] changanluan commented on issue #24460: SQLServer 2012 page query java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

Posted by "changanluan (via GitHub)" <gi...@apache.org>.
changanluan commented on issue #24460:
URL: https://github.com/apache/shardingsphere/issues/24460#issuecomment-1466092090

   The sql I used is "select wfconsumer0_.WC029_GUID as col_0_0_ from WF029_CONSUMEELOG wfconsumer0_ where 1=1 and wfconsumer0_.WC029_STATE=1 order by col_11_0_ desc",  "offset ? rows fetch next ? rows only" is added by hibernate.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [I] SQLServer 2012 page query java.lang.IndexOutOfBoundsException: Index: 2, Size: 2 [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu closed issue #24460: SQLServer 2012 page query java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
URL: https://github.com/apache/shardingsphere/issues/24460


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

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