本文介绍了Spring批处理中的JdbcPagingItemReader没有给出正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题是,我从 query pagination 配置中返回了记录,但我给出了错误的记录号.分页配置不正确.分页返回较少的记录.

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.

select *from SOME_TABLEwhere CLIENT_FILE_NM= 'process_abc.20150617024850' AND TXN_ID IS NOT NULL AND SOME_DATA IS NOT NULL order by CREATE_DT ASC;

select *from SOME_TABLEwhere CLIENT_FILE_NM= 'process_abc.20150617024850' AND TXN_ID IS NOT NULL AND SOME_DATA IS NOT NULL order by CREATE_DT ASC;

     <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>

推荐答案

问题已解决,因为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))

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))

记录将丢失.

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

<property name="sortKey" value="CREATE_DT" /> // this was not unique ...

这篇关于Spring批处理中的JdbcPagingItemReader没有给出正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:35