0

I am using JdbcPagingItemReader as below,

@Bean
    public ItemReader<RemittanceVO> reader() {

        JdbcPagingItemReader<RemittanceVO> reader = new   JdbcPagingItemReader<RemittanceVO>();
        reader.setDataSource(dataSource);
        reader.setRowMapper(new RemittanceRowMapper());
        reader.setQueryProvider(queryProvider);
        reader.setPageSize(100);
        return reader;
    }


@Bean
    public PagingQueryProvider queryProvider() throws Exception{
        SqlPagingQueryProviderFactoryBean queryProviderBean= new SqlPagingQueryProviderFactoryBean();
        queryProviderBean.setDataSource(dataSource);
        queryProviderBean.setSelectClause(Constants.REMITTANCES_SELECT_CLAUSE);
        queryProviderBean.setFromClause(Constants.REMITTANCES_FROM_CLAUSE);
        queryProviderBean.setWhereClause(Constants.REMITTANCES_WHERE_CLAUSE);
        queryProviderBean.setSortKey(Constants.REMITTANCES_SORT_KEY);
        PagingQueryProvider queryProvider = queryProviderBean.getObject();
        return queryProvider;
    }

As of now, I launch job as below ( as I am very new to Spring batch )

JobLauncher jobLauncher = (JobLauncher) ctx.getBean("jobLauncher");
        Job job = (Job) ctx.getBean("runRCMatcher");

        try {
            JobExecution execution = jobLauncher.run(job, new JobParameters());
        }catch (Exception e) {
            e.printStackTrace();
        }

I am running this app as SpringBoot app. It fetches first 100 records successfully and hands over to processor and then next query fails. Query fails because sort key value has not been placed in it. This is there in query , AND ((REMIT_ID > ?)) ORDER BY REMIT_ID ASC FETCH FIRST 100 ROWS ONLY;

Where am I wrong?

My DB is DB2 so I guess it should be using - Db2PagingQueryProvider

Step & Job are defined as ,

@Bean
        public Step step1(StepBuilderFactory stepBuilderFactory,
                ItemReader<RemittanceVO> reader, ItemWriter<RemittanceClaimVO> writer,
                ItemProcessor<RemittanceVO, RemittanceClaimVO> processor) {

            return stepBuilderFactory.get("step1")
                    .<RemittanceVO, RemittanceClaimVO> chunk(100).reader(reader)
                    .processor(processor).writer(writer).build();
        }


@Bean
    public Job runRCMatcher(JobBuilderFactory jobs, Step s1) {
        return jobs.get("RCMatcher")
                .incrementer(new RunIdIncrementer())
                .flow(s1)
                .end()
                .build();
    }

Sort key specified is table column name - Constants.REMITTANCES_SORT_KEY and that is a primary key of table and of type BIGINT

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
  • Seems like your code is correct and has nothing wrong with spring batch configuration. Can it be the case that REMIT_ID has null value? – featuredpeow Aug 22 '16 at 15:50
  • REMIT_ID is a DB2 generated sequence so not likely to be null. – Sabir Khan Aug 23 '16 at 03:40
  • my error is duplicate of what is mentioned [here](http://forum.spring.io/forum/spring-projects/batch/107625-batch-jdbcpagingitemreader-not-passing-starting-index-on-second-page) – Sabir Khan Aug 23 '16 at 04:14
  • I should have specified full stack trace here. My problem was using an alias column name in WHERE clause. REMIT_ID was an alias for PAYMENT_ID and I was specifying REMIT_ID as sort key, [Referring to a Column Alias in a WHERE Clause](http://stackoverflow.com/questions/8370114/referring-to-a-column-alias-in-a-where-clause). Removing that alias and changing sort key to PAYMENT_ID solved issue. – Sabir Khan Aug 23 '16 at 05:47

0 Answers0