问题
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>
回答1:
Issue got resolved as sortKey has to be unique key. Spring create query in below format :
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))
and records will be missed.
<property name="sortKey" value="CREATE_DT" /> // this was not unique ...
回答2:
Check your data on the database. I think the problem is related to the IS NOT NULL comparisons, depending on your database engine and table definitions NULL can be interpreted in different ways. Try to compare TXN_ID != '', or > 0 depending on your data type.
来源:https://stackoverflow.com/questions/31058678/jdbcpagingitemreader-in-spring-batch-is-not-giving-correct-results