JdbcPagingItemReader in Spring batch is not giving correct results

时间:2015-06-25 19:02:19

标签: spring oracle spring-batch

I am facing issue that records return from query and pagination config i made giving incorrect no's of records. Is pagination config incorrect. pagination return less no of records. Query equivalent of paging config select * from SOME_TABLE where CLIENT_FILE_NM= 'process_abc.20150617024850' AND TXN_ID IS NOT NULL AND SOME_DATA IS NOT NULL order by CREATE_DT ASC; Paging config <bean id="postItemReader" 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="select *" /> <property name="fromClause" value="from SOME_TABLE" /> <property name="whereClause" value="CLIENT_FILE_NM= :fileName AND TXN_ID IS NOT NULL AND SOME_DATA IS NOT NULL" /> <property name="sortKey" value="CREATE_DT" /> <!-- CARD_SETTL_STG_ID_PK ASC --> </bean> </property> <property name="parameterValues"> <map> <entry key="fileName" value="# {jobParameters['fileName']}" /> </map> </property> <property name="pageSize" value="10" /> <property name="rowMapper"> <bean class="com.wdpr.payment.batch.mapper.OutputVOMapper" /> </property> <property name="saveState" value="false"/> </bean>

2 个答案:

答案 0 :(得分:2)

问题得到解决,因为sortKey必须是唯一键。 Spring以下面的格式创建查询: SELECT * FROM (SELECT * FROM CRD_SETTL WHERE CLIENT_FILE_NM= :fileName AND TXN_ID IS NOT NULL AND SETTL_DATA IS NOT NULL ORDER BY CREATE_DT ASC) WHERE ROWNUM <= 10 AND ((CREATE_DT > :_CREATE_DT))

并且会遗漏记录。

<property name="sortKey" value="CREATE_DT" /> //这不是唯一的...

答案 1 :(得分:0)

检查数据库中的数据。我认为问题与IS NOT NULL比较有关,取决于您的数据库引擎和表定义,NULL可以用不同的方式解释。尝试比较TXN_ID!=''或&gt; 0取决于您的数据类型。