Spring batch: JdbcPagingItemReader doesn't obtain page 1 onwards

余生长醉 提交于 2020-12-15 00:29:26

问题


Here my reader:

@Bean
public ItemReader<Unitat> itemReader(PagingQueryProvider queryProvider) {
    return new JdbcPagingItemReaderBuilder<Unitat>()
        .name("creditReader")
        .dataSource(this.dataSource)
        .queryProvider(queryProvider)
        .rowMapper(this.unitatMapper)
        .pageSize(2)
        .build();
}

@Bean
    public SqlPagingQueryProviderFactoryBean queryProvider() {
        SqlPagingQueryProviderFactoryBean provider = new SqlPagingQueryProviderFactoryBean();

        provider.setDataSource(this.dataSource);
        provider.setSelectClause("SELECT im_notext1.nt1_id");
        provider.setFromClause("FROM im_notext1 LEFT OUTER JOIN im_notext2 ON im_notext1.nt1_id = im_notext2.nt1_id");
        provider.setSortKey("nt1_id");

        return provider;
    }

Formatted query is:

SELECT
  TOP 2 im_notext1.nt1_id
FROM
  im_notext1
  LEFT OUTER JOIN im_notext2 ON im_notext1.nt1_id = im_notext2.nt1_id
ORDER BY
  nt1_id ASC

I know, it seems a dummy query. Only for simplifying context.

Shortly, PagingQueryProvider is engaged to generate "paged queries" like:

Page 0:

SELECT
  TOP 2 im_notext1.nt1_id
FROM
  im_notext1
  LEFT OUTER JOIN im_notext2 ON im_notext1.nt1_id = im_notext2.nt1_id
ORDER BY
  nt1_id ASC

Page 1:

SELECT
  TOP 2 im_notext1.nt1_id
FROM
  im_notext1
  LEFT OUTER JOIN im_notext2 ON im_notext1.nt1_id = im_notext2.nt1_id
WHERE
  ((nt1_id > ?))
ORDER BY
  nt1_id ASC

I've activated logs:

logging.level.org.springframework.batch.item.database=debug

I'm getting this error message:

com.microsoft.sqlserver.jdbc.SQLServerException: Ambiguous column name 'nt1_id'.

Really, nt1_id column is on both im_notext1 and im_notext2 tables (joined on from clause).

Logs:

Reading page 0
SQL used for reading first page: [SELECT TOP 2 im_notext1.nt1_id FROM im_notext1 LEFT OUTER JOIN im_notext2 ON im_notext1.nt1_id = im_notext2.nt1_id ORDER BY nt1_id ASC]
Reading page 1
SQL used for reading remaining pages: [SELECT TOP 2 im_notext1.nt1_id FROM im_notext1 LEFT OUTER JOIN im_notext2 ON im_notext1.nt1_id = im_notext2.nt1_id WHERE ((nt1_id > ?)) ORDER BY nt1_id ASC]
Using parameterList:[244029]

Any ideas?

来源:https://stackoverflow.com/questions/64928337/spring-batch-jdbcpagingitemreader-doesnt-obtain-page-1-onwards

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