Spring Batch JdbcPagingItemReader seems not paginating

匿名 (未验证) 提交于 2019-12-03 10:24:21

问题:

I'm working on an app that indexes a bunch of files in an embedded Derby(10.12.1.1) DB and then are exported as one single tabulated file. The first part is working fine since the DB is created and all records are indexed.

However, when I attempt to read from the DB using JdbcPagingItemReader and write to a file I only get the number of records specified in pageSize. So if the pageSize is 10, then I get a file with 10 lines and the rest of the records seem to be ignored. So far, I haven't been able to find whats is really going on and any help would be most welcome.

Here is the JdbcPagingItemReader config:

<!-- DB Item Reader -->     <bean id="pagingItemReader" class="org.springframework.batch.item.database.JdbcPagingItemReader" scope="step">         <property name="dataSource" ref="dataSource" />         <property name="queryProvider">             <bean class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">                 <property name="dataSource" ref="dataSource" />                 <property name="selectClause">                     <value>                         <![CDATA[                         SAMPLE.ID, SAMPLE.PARENT_SAMPLE_ID, SAMPLE.MATERIAL_TYPE, SAMPLE.CONTAINER, SAMPLE.STORAGE_TEMPERATURE, SAMPLE.SAMPLED_TIME, SAMPLE.ANATOMICAL_SITE_ONTOLOGY, SAMPLE.ANATOMICAL_SITE_VERSION, SAMPLE.ANATOMICAL_SITE_CODE, SAMPLE.ANATOMICAL_SITE_DESCRIPTION, SAMPLE.ONTOLOGY_ONTOLOGY, SAMPLE.ONTOLOGY_VERSION, SAMPLE.ONTOLOGY_CODE, SAMPLE.ONTOLOGY_DESCRIPTION, SAMPLE.ONTOLOGY_FREE_TEXT, SAMPLE.SEX, SAMPLE.AGE_LOW, SAMPLE.AGE_HIGH, SAMPLE.AGE_UNIT,                         BIOBANK.ID AS BIOBANK_ID, BIOBANK.ACRONYM, BIOBANK.NAME, BIOBANK.URL, BIOBANK.JURISTIC_PERSON, BIOBANK.COUNTRY AS BIOBANK_COUNTRY, BIOBANK.DESCRIPTION,                         BB_CI.ID AS BB_CI_ID, BB_CI.FIRST_NAME AS BB_CI_FIRST_NAME, BB_CI.LAST_NAME AS BB_CI_LAST_NAME, BB_CI.PHONE AS BB_CI_PHONE, BB_CI.EMAIL AS BB_CI_EMAIL, BB_CI.ADDRESS AS BB_CI_ADDRESS, BB_CI.ZIP AS BB_CI_ZIP, BB_CI.CITY AS BB_CI_CITY, BB_CI.COUNTRY AS BB_CI_COUNTRY,                         STUDY.ID AS STUDY_ID, STUDY.NAME AS STUDY_NAME, STUDY.DESCRIPTION AS STUDY_DESCRIPTION, STUDY.STUDY_DESIGN AS STUDY_STUDY_DESIGN, STUDY.DATA_CATEGORY AS STUDY_DATA_CATEGORY, STUDY.TOTAL_NUMBER_OF_PARTICIPANTS, STUDY.TOTAL_NUMBER_OF_DONORS, STUDY.INCLUSION_CRITERIA, STUDY.PRINCIPAL_INVESTIGATOR,                         S_CI.ID AS S_CI_ID, S_CI.FIRST_NAME AS S_CI_FIRST_NAME, S_CI.LAST_NAME AS S_CI_LAST_NAME, S_CI.PHONE AS S_CI_PHONE, S_CI.EMAIL AS S_CI_EMAIL, S_CI.ADDRESS AS S_CI_ADDRESS, S_CI.ZIP AS S_CI_ZIP, S_CI.CITY AS S_CI_CITY, S_CI.COUNTRY AS S_CI_COUNTRY,                         SAMPLE_COLLECTION.ID AS SAMPLE_COLLECTION_ID, SAMPLE_COLLECTION.ACRONYM AS SAMPLE_COLLECTION_ACRONYM, SAMPLE_COLLECTION.NAME AS SAMPLE_COLLECTION_NAME, SAMPLE_COLLECTION.DESCRIPTION AS SAMPLE_COLLECTION_DESCRIPTION, SAMPLE_COLLECTION.DATA_CATEGORY AS SAMPLE_COLLECTION_DATA_CATEGORY, SAMPLE_COLLECTION.COLLECTION_TYPE AS SAMPLE_COLLECTION_COLLECTION_TYPE,                         SC_CI.ID AS SC_CI_ID, SC_CI.FIRST_NAME AS SC_CI_FIRST_NAME, SC_CI.LAST_NAME AS SC_CI_LAST_NAME, SC_CI.PHONE AS SC_CI_PHONE, SC_CI.EMAIL AS SC_CI_EMAIL, SC_CI.ADDRESS AS SC_CI_ADDRESS, SC_CI.ZIP AS SC_CI_ZIP, SC_CI.CITY AS SC_CI_CITY, SC_CI.COUNTRY AS SC_CI_COUNTRY                         ]]>                     </value>                 </property>                 <property name="fromClause">                     <value>                         <![CDATA[                             SAMPLE                             LEFT JOIN BIOBANK ON SAMPLE.BIOBANK = BIOBANK.ID                             LEFT JOIN CONTACT_INFORMATION AS BB_CI ON BIOBANK.CONTACT_INFORMATION = BB_CI.ID                             LEFT JOIN STUDY ON SAMPLE.STUDY = STUDY.ID                             LEFT JOIN CONTACT_INFORMATION AS S_CI ON STUDY.CONTACT_INFORMATION = S_CI.ID                             LEFT JOIN SAMPLE_COLLECTION ON SAMPLE.SAMPLE_COLLECTION = SAMPLE_COLLECTION.ID                              LEFT JOIN CONTACT_INFORMATION AS SC_CI ON SAMPLE_COLLECTION.CONTACT_INFORMATION = SC_CI.ID                         ]]>                     </value>                 </property>                 <property name="sortKey" value="ID" />             </bean>         </property>         <property name="pageSize" value="100" />         <property name="rowMapper">             <bean class="org.miabis.converter.batch.database.SampleRowMapper" />         </property>   </bean> 

And here is the job config:

<batch:job id="job1">         <batch:step id="step1" next="step2">                         <batch:tasklet transaction-manager="transactionManager" start-limit="100" >                 <batch:chunk reader="contactInfoReader" writer="contactInfoWriter" commit-interval="100" />             </batch:tasklet>         </batch:step>          <batch:step id="step2" next="step3">                         <batch:tasklet transaction-manager="transactionManager" start-limit="100" >                 <batch:chunk reader="biobankReader" writer="biobankWriter" commit-interval="100" />             </batch:tasklet>         </batch:step>          <batch:step id="step3" next="step4">                         <batch:tasklet transaction-manager="transactionManager" start-limit="100" >                 <batch:chunk reader="sampleCollectionReader" writer="sampleCollectionWriter" commit-interval="100" />             </batch:tasklet>         </batch:step>          <batch:step id="step4" next="step5">                         <batch:tasklet transaction-manager="transactionManager" start-limit="100" >                 <batch:chunk reader="studyReader" writer="studyWriter" commit-interval="100" />             </batch:tasklet>         </batch:step>          <batch:step id="step5" next="step6">                         <batch:tasklet transaction-manager="transactionManager" start-limit="100" >                 <batch:chunk reader="sampleReader" writer="sampleWriter" commit-interval="100" />             </batch:tasklet>         </batch:step>          <batch:step id="step6">                      <batch:tasklet transaction-manager="transactionManager" start-limit="100" >                 <batch:chunk reader="pagingItemReader" writer="tabFileItemWriter" commit-interval="100" />             </batch:tasklet>         </batch:step>      </batch:job> 

Edit

Based on Hansjoerg Wingeier's suggestions I matched the commit-interval in step 6 with the pageSize in JdbcPagingItemReader config. Additionally, I extended the JdbcPagingItemReader just to log how may times the method doReadPage is called. As it turns out, its only called twice but the rowmapper only gets the items from the first page.

Also, I tried to use a JdbcCursorItemReader but it throws a SQL exception that says The 'getRow()' method is only allowed on scroll cursors.

Here is the JdbcCursorItemReader congig:

<bean id="itemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">     <property name="dataSource" ref="dataSource" />     <property name="sql">         <value>                     <![CDATA[                         select                             SAMPLE.ID, SAMPLE.PARENT_SAMPLE_ID, SAMPLE.MATERIAL_TYPE, SAMPLE.CONTAINER, SAMPLE.STORAGE_TEMPERATURE, SAMPLE.SAMPLED_TIME, SAMPLE.ANATOMICAL_SITE_ONTOLOGY, SAMPLE.ANATOMICAL_SITE_VERSION, SAMPLE.ANATOMICAL_SITE_CODE, SAMPLE.ANATOMICAL_SITE_DESCRIPTION, SAMPLE.ONTOLOGY_ONTOLOGY, SAMPLE.ONTOLOGY_VERSION, SAMPLE.ONTOLOGY_CODE, SAMPLE.ONTOLOGY_DESCRIPTION, SAMPLE.ONTOLOGY_FREE_TEXT, SAMPLE.SEX, SAMPLE.AGE_LOW, SAMPLE.AGE_HIGH, SAMPLE.AGE_UNIT,                             BIOBANK.ID AS BIOBANK_ID, BIOBANK.ACRONYM, BIOBANK.NAME, BIOBANK.URL, BIOBANK.JURISTIC_PERSON, BIOBANK.COUNTRY AS BIOBANK_COUNTRY, BIOBANK.DESCRIPTION,                             BB_CI.ID AS BB_CI_ID, BB_CI.FIRST_NAME AS BB_CI_FIRST_NAME, BB_CI.LAST_NAME AS BB_CI_LAST_NAME, BB_CI.PHONE AS BB_CI_PHONE, BB_CI.EMAIL AS BB_CI_EMAIL, BB_CI.ADDRESS AS BB_CI_ADDRESS, BB_CI.ZIP AS BB_CI_ZIP, BB_CI.CITY AS BB_CI_CITY, BB_CI.COUNTRY AS BB_CI_COUNTRY,                             STUDY.ID AS STUDY_ID, STUDY.NAME AS STUDY_NAME, STUDY.DESCRIPTION AS STUDY_DESCRIPTION, STUDY.STUDY_DESIGN AS STUDY_STUDY_DESIGN, STUDY.DATA_CATEGORY AS STUDY_DATA_CATEGORY, STUDY.TOTAL_NUMBER_OF_PARTICIPANTS, STUDY.TOTAL_NUMBER_OF_DONORS, STUDY.INCLUSION_CRITERIA, STUDY.PRINCIPAL_INVESTIGATOR,                             S_CI.ID AS S_CI_ID, S_CI.FIRST_NAME AS S_CI_FIRST_NAME, S_CI.LAST_NAME AS S_CI_LAST_NAME, S_CI.PHONE AS S_CI_PHONE, S_CI.EMAIL AS S_CI_EMAIL, S_CI.ADDRESS AS S_CI_ADDRESS, S_CI.ZIP AS S_CI_ZIP, S_CI.CITY AS S_CI_CITY, S_CI.COUNTRY AS S_CI_COUNTRY,                             SAMPLE_COLLECTION.ID AS SAMPLE_COLLECTION_ID, SAMPLE_COLLECTION.ACRONYM AS SAMPLE_COLLECTION_ACRONYM, SAMPLE_COLLECTION.NAME AS SAMPLE_COLLECTION_NAME, SAMPLE_COLLECTION.DESCRIPTION AS SAMPLE_COLLECTION_DESCRIPTION, SAMPLE_COLLECTION.DATA_CATEGORY AS SAMPLE_COLLECTION_DATA_CATEGORY, SAMPLE_COLLECTION.COLLECTION_TYPE AS SAMPLE_COLLECTION_COLLECTION_TYPE,                             SC_CI.ID AS SC_CI_ID, SC_CI.FIRST_NAME AS SC_CI_FIRST_NAME, SC_CI.LAST_NAME AS SC_CI_LAST_NAME, SC_CI.PHONE AS SC_CI_PHONE, SC_CI.EMAIL AS SC_CI_EMAIL, SC_CI.ADDRESS AS SC_CI_ADDRESS, SC_CI.ZIP AS SC_CI_ZIP, SC_CI.CITY AS SC_CI_CITY, SC_CI.COUNTRY AS SC_CI_COUNTRY                          from                             SAMPLE                             LEFT JOIN BIOBANK ON SAMPLE.BIOBANK = BIOBANK.ID                             LEFT JOIN CONTACT_INFORMATION AS BB_CI ON BIOBANK.CONTACT_INFORMATION = BB_CI.ID                             LEFT JOIN STUDY ON SAMPLE.STUDY = STUDY.ID                             LEFT JOIN CONTACT_INFORMATION AS S_CI ON STUDY.CONTACT_INFORMATION = S_CI.ID                             LEFT JOIN SAMPLE_COLLECTION ON SAMPLE.SAMPLE_COLLECTION = SAMPLE_COLLECTION.ID                              LEFT JOIN CONTACT_INFORMATION AS SC_CI ON SAMPLE_COLLECTION.CONTACT_INFORMATION = SC_CI.ID                     ]]>                 </value>     </property>     <property name="rowMapper">         <bean class="org.miabis.converter.batch.database.SampleRowMapper" />     </property> </bean> 

And here is the full exception:

    [main] INFO org.springframework.batch.core.job.SimpleStepHandler - Executing step: [step6] [main] INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml] [main] INFO org.springframework.jdbc.support.SQLErrorCodesFactory - SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana] [main] ERROR org.springframework.batch.core.step.AbstractStep - Encountered an error executing step step6 in job job1 org.springframework.jdbc.UncategorizedSQLException: Attempt to process next row failed; uncategorized SQLException for SQL [                              select                                 SAMPLE.ID, SAMPLE.PARENT_SAMPLE_ID, SAMPLE.MATERIAL_TYPE, SAMPLE.CONTAINER, SAMPLE.STORAGE_TEMPERATURE, SAMPLE.SAMPLED_TIME, SAMPLE.ANATOMICAL_SITE_ONTOLOGY, SAMPLE.ANATOMICAL_SITE_VERSION, SAMPLE.ANATOMICAL_SITE_CODE, SAMPLE.ANATOMICAL_SITE_DESCRIPTION, SAMPLE.ONTOLOGY_ONTOLOGY, SAMPLE.ONTOLOGY_VERSION, SAMPLE.ONTOLOGY_CODE, SAMPLE.ONTOLOGY_DESCRIPTION, SAMPLE.ONTOLOGY_FREE_TEXT, SAMPLE.SEX, SAMPLE.AGE_LOW, SAMPLE.AGE_HIGH, SAMPLE.AGE_UNIT,                                 BIOBANK.ID AS BIOBANK_ID, BIOBANK.ACRONYM, BIOBANK.NAME, BIOBANK.URL, BIOBANK.JURISTIC_PERSON, BIOBANK.COUNTRY AS BIOBANK_COUNTRY, BIOBANK.DESCRIPTION,                                 BB_CI.ID AS BB_CI_ID, BB_CI.FIRST_NAME AS BB_CI_FIRST_NAME, BB_CI.LAST_NAME AS BB_CI_LAST_NAME, BB_CI.PHONE AS BB_CI_PHONE, BB_CI.EMAIL AS BB_CI_EMAIL, BB_CI.ADDRESS AS BB_CI_ADDRESS, BB_CI.ZIP AS BB_CI_ZIP, BB_CI.CITY AS BB_CI_CITY, BB_CI.COUNTRY AS BB_CI_COUNTRY,                                 STUDY.ID AS STUDY_ID, STUDY.NAME AS STUDY_NAME, STUDY.DESCRIPTION AS STUDY_DESCRIPTION, STUDY.STUDY_DESIGN AS STUDY_STUDY_DESIGN, STUDY.DATA_CATEGORY AS STUDY_DATA_CATEGORY, STUDY.TOTAL_NUMBER_OF_PARTICIPANTS, STUDY.TOTAL_NUMBER_OF_DONORS, STUDY.INCLUSION_CRITERIA, STUDY.PRINCIPAL_INVESTIGATOR,                                 S_CI.ID AS S_CI_ID, S_CI.FIRST_NAME AS S_CI_FIRST_NAME, S_CI.LAST_NAME AS S_CI_LAST_NAME, S_CI.PHONE AS S_CI_PHONE, S_CI.EMAIL AS S_CI_EMAIL, S_CI.ADDRESS AS S_CI_ADDRESS, S_CI.ZIP AS S_CI_ZIP, S_CI.CITY AS S_CI_CITY, S_CI.COUNTRY AS S_CI_COUNTRY,                                 SAMPLE_COLLECTION.ID AS SAMPLE_COLLECTION_ID, SAMPLE_COLLECTION.ACRONYM AS SAMPLE_COLLECTION_ACRONYM, SAMPLE_COLLECTION.NAME AS SAMPLE_COLLECTION_NAME, SAMPLE_COLLECTION.DESCRIPTION AS SAMPLE_COLLECTION_DESCRIPTION, SAMPLE_COLLECTION.DATA_CATEGORY AS SAMPLE_COLLECTION_DATA_CATEGORY, SAMPLE_COLLECTION.COLLECTION_TYPE AS SAMPLE_COLLECTION_COLLECTION_TYPE,                                 SC_CI.ID AS SC_CI_ID, SC_CI.FIRST_NAME AS SC_CI_FIRST_NAME, SC_CI.LAST_NAME AS SC_CI_LAST_NAME, SC_CI.PHONE AS SC_CI_PHONE, SC_CI.EMAIL AS SC_CI_EMAIL, SC_CI.ADDRESS AS SC_CI_ADDRESS, SC_CI.ZIP AS SC_CI_ZIP, SC_CI.CITY AS SC_CI_CITY, SC_CI.COUNTRY AS SC_CI_COUNTRY                              from                                 SAMPLE                                 LEFT JOIN BIOBANK ON SAMPLE.BIOBANK = BIOBANK.ID                                 LEFT JOIN CONTACT_INFORMATION AS BB_CI ON BIOBANK.CONTACT_INFORMATION = BB_CI.ID                                 LEFT JOIN STUDY ON SAMPLE.STUDY = STUDY.ID                                 LEFT JOIN CONTACT_INFORMATION AS S_CI ON STUDY.CONTACT_INFORMATION = S_CI.ID                                 LEFT JOIN SAMPLE_COLLECTION ON SAMPLE.SAMPLE_COLLECTION = SAMPLE_COLLECTION.ID                                  LEFT JOIN CONTACT_INFORMATION AS SC_CI ON SAMPLE_COLLECTION.CONTACT_INFORMATION = SC_CI.ID                      ]; SQL state [XJ061]; error code [20000]; The 'getRow()' method is only allowed on scroll cursors.; nested exception is java.sql.SQLException: The 'getRow()' method is only allowed on scroll cursors.     at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)     at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)     at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)     at org.springframework.batch.item.database.AbstractCursorItemReader.doRead(AbstractCursorItemReader.java:456)     at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:88)     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:497)     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)     at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)     at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)     at com.sun.proxy.$Proxy18.read(Unknown Source)     at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91)     at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:157)     at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:116)     at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)     at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)     at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)     at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:110)     at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69)     at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)     at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)     at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)     at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)     at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)     at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)     at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)     at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)     at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)     at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)     at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)     at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)     at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)     at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)     at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)     at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)     at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)     at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)     at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)     at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)     at org.miabis.converter.JobFilesDBTabTest.testLaunchJob(JobFilesDBTabTest.java:43)     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:497)     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)     at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)     at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)     at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)     at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)     at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.sql.SQLException: The 'getRow()' method is only allowed on scroll cursors.     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)     at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)     at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)     at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)     at org.apache.derby.impl.jdbc.EmbedResultSet.checkScrollCursor(Unknown Source)     at org.apache.derby.impl.jdbc.EmbedResultSet.getRow(Unknown Source)     at org.springframework.batch.item.database.AbstractCursorItemReader.verifyCursorPosition(AbstractCursorItemReader.java:367)     at org.springframework.batch.item.database.AbstractCursorItemReader.doRead(AbstractCursorItemReader.java:452)     ... 71 more Caused by: ERROR XJ061: The 'getRow()' method is only allowed on scroll cursors.     at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)     at org.apache.derby.impl.jdbc.SQLExceptionFactory.wrapArgsForTransportAcrossDRDA(Unknown Source)     ... 79 more 

回答1:

Following Hansjoerg Wingeier's suggestions I decided to use a JdbcCursorItemReader and solved the UncategorizedSQLException by setting verifyCursorPosition=false as described here.

This is the final configuration for JdbcCursorItemReader:

<bean id="jdbcCursorItemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader" scope="step">         <property name="dataSource" ref="dataSource" />         <property name="sql">             <value>                         <![CDATA[                             select                                 SAMPLE.ID, SAMPLE.PARENT_SAMPLE_ID, SAMPLE.MATERIAL_TYPE, SAMPLE.CONTAINER, SAMPLE.STORAGE_TEMPERATURE, SAMPLE.SAMPLED_TIME, SAMPLE.ANATOMICAL_SITE_ONTOLOGY, SAMPLE.ANATOMICAL_SITE_VERSION, SAMPLE.ANATOMICAL_SITE_CODE, SAMPLE.ANATOMICAL_SITE_DESCRIPTION, SAMPLE.ONTOLOGY_ONTOLOGY, SAMPLE.ONTOLOGY_VERSION, SAMPLE.ONTOLOGY_CODE, SAMPLE.ONTOLOGY_DESCRIPTION, SAMPLE.ONTOLOGY_FREE_TEXT, SAMPLE.SEX, SAMPLE.AGE_LOW, SAMPLE.AGE_HIGH, SAMPLE.AGE_UNIT,                                 BIOBANK.ID AS BIOBANK_ID, BIOBANK.ACRONYM, BIOBANK.NAME, BIOBANK.URL, BIOBANK.JURISTIC_PERSON, BIOBANK.COUNTRY AS BIOBANK_COUNTRY, BIOBANK.DESCRIPTION,                                 BB_CI.ID AS BB_CI_ID, BB_CI.FIRST_NAME AS BB_CI_FIRST_NAME, BB_CI.LAST_NAME AS BB_CI_LAST_NAME, BB_CI.PHONE AS BB_CI_PHONE, BB_CI.EMAIL AS BB_CI_EMAIL, BB_CI.ADDRESS AS BB_CI_ADDRESS, BB_CI.ZIP AS BB_CI_ZIP, BB_CI.CITY AS BB_CI_CITY, BB_CI.COUNTRY AS BB_CI_COUNTRY,                                 STUDY.ID AS STUDY_ID, STUDY.NAME AS STUDY_NAME, STUDY.DESCRIPTION AS STUDY_DESCRIPTION, STUDY.STUDY_DESIGN AS STUDY_STUDY_DESIGN, STUDY.DATA_CATEGORY AS STUDY_DATA_CATEGORY, STUDY.TOTAL_NUMBER_OF_PARTICIPANTS, STUDY.TOTAL_NUMBER_OF_DONORS, STUDY.INCLUSION_CRITERIA, STUDY.PRINCIPAL_INVESTIGATOR,                                 S_CI.ID AS S_CI_ID, S_CI.FIRST_NAME AS S_CI_FIRST_NAME, S_CI.LAST_NAME AS S_CI_LAST_NAME, S_CI.PHONE AS S_CI_PHONE, S_CI.EMAIL AS S_CI_EMAIL, S_CI.ADDRESS AS S_CI_ADDRESS, S_CI.ZIP AS S_CI_ZIP, S_CI.CITY AS S_CI_CITY, S_CI.COUNTRY AS S_CI_COUNTRY,                                 SAMPLE_COLLECTION.ID AS SAMPLE_COLLECTION_ID, SAMPLE_COLLECTION.ACRONYM AS SAMPLE_COLLECTION_ACRONYM, SAMPLE_COLLECTION.NAME AS SAMPLE_COLLECTION_NAME, SAMPLE_COLLECTION.DESCRIPTION AS SAMPLE_COLLECTION_DESCRIPTION, SAMPLE_COLLECTION.DATA_CATEGORY AS SAMPLE_COLLECTION_DATA_CATEGORY, SAMPLE_COLLECTION.COLLECTION_TYPE AS SAMPLE_COLLECTION_COLLECTION_TYPE,                                 SC_CI.ID AS SC_CI_ID, SC_CI.FIRST_NAME AS SC_CI_FIRST_NAME, SC_CI.LAST_NAME AS SC_CI_LAST_NAME, SC_CI.PHONE AS SC_CI_PHONE, SC_CI.EMAIL AS SC_CI_EMAIL, SC_CI.ADDRESS AS SC_CI_ADDRESS, SC_CI.ZIP AS SC_CI_ZIP, SC_CI.CITY AS SC_CI_CITY, SC_CI.COUNTRY AS SC_CI_COUNTRY                              from                                 SAMPLE                                 LEFT JOIN BIOBANK ON SAMPLE.BIOBANK = BIOBANK.ID                                 LEFT JOIN CONTACT_INFORMATION AS BB_CI ON BIOBANK.CONTACT_INFORMATION = BB_CI.ID                                 LEFT JOIN STUDY ON SAMPLE.STUDY = STUDY.ID                                 LEFT JOIN CONTACT_INFORMATION AS S_CI ON STUDY.CONTACT_INFORMATION = S_CI.ID                                 LEFT JOIN SAMPLE_COLLECTION ON SAMPLE.SAMPLE_COLLECTION = SAMPLE_COLLECTION.ID                                  LEFT JOIN CONTACT_INFORMATION AS SC_CI ON SAMPLE_COLLECTION.CONTACT_INFORMATION = SC_CI.ID                              order by SAMPLE.ID                         ]]>                     </value>         </property>         <property name="rowMapper">             <bean class="org.miabis.converter.batch.database.SampleRowMapper" />         </property>         <property name="verifyCursorPosition" value="false"/>     </bean> 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!