我正在 Liberty Profile 中试验 JSR-352 实现,并且在我的阅读器处理了我的 JDBC ResultSet 的前 10 个项目后,我被“ORA-01002: fetch out of sequence”错误所困扰。我的块大小设置为 100。
这是我的读者:
@Dependent
@Named("myItemReader")
public class MyItemReader extends AbstractItemReader {
@Resource(name="jdbc/somedb",shareable=false)
private DataSource lavDb;
private PreparedStatement stmt;
private ResultSet rs;
@Override
public void open(Serializable checkpoint) throws Exception {
Connection con = lavDb.getConnection();
con.setAutoCommit(false);
stmt = con.prepareStatement("select id from sometable",
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery();
}
@Override
public MyInputRecord readItem() throws Exception{
if(rs.next()){
return new MyInputRecord(rs.getInt(1));
}
return null;
}
@Override
public void close(){
try{
rs.close();
stmt.close();
}
catch(Exception e){
e.printStackTrace();
}
}
}
如果 ResultSet 处理发生在 open() 方法中,那么我不会遇到任何错误。
这是我的 server.xml 中的 batchPersistence 配置:
<dataSource id="oracle-wasadmin" jdbcDriverRef="wasoracledriver" jndiName="jdbc/wasoracledb" type="javax.sql.XADataSource">
<properties.oracle URL="${wasadmin.jdbcurl}" password="xxxxxx" user="yyyyyy"/>
<conionManager agedTimeout="1m" maxIdleTime="15m" maxPoolSize="25" minPoolSize="0"/>
</dataSource>
<jdbcDriver id="wasoracledriver" javax.sql.XADataSource="oracle.jdbc.xa.client.OracleXADataSource">
<library>
<fileset dir="${shared.resource.dir}/oracle" includes="*.jar"/>
</library>
</jdbcDriver>
这是作业日志中的错误:
com.ibm.jbatch.container.exception.BatchContainerRuntimeException: Failure in Read-Process-Write Loop
at com.ibm.jbatch.container.controller.impl.ChunkStepControllerImpl.invokeChunk(ChunkStepControllerImpl.java:702)
at com.ibm.jbatch.container.controller.impl.ChunkStepControllerImpl.invokeCoreStep(ChunkStepControllerImpl.java:792)
at com.ibm.jbatch.container.controller.impl.BaseStepControllerImpl.execute(BaseStepControllerImpl.java:292)
at com.ibm.jbatch.container.controller.impl.ExecutionTransitioner.doExecutionLoop(ExecutionTransitioner.java:118)
at com.ibm.jbatch.container.controller.impl.WorkUnitThreadControllerImpl.executeCoreTransitionLoop(WorkUnitThreadControllerImpl.java:94)
at com.ibm.jbatch.container.controller.impl.WorkUnitThreadControllerImpl.executeWorkUnit(WorkUnitThreadControllerImpl.java:155)
at com.ibm.jbatch.container.controller.impl.WorkUnitThreadControllerImpl$AbstractControllerHelper.runExecutionOnThread(WorkUnitThreadControllerImpl.java:480)
at com.ibm.jbatch.container.controller.impl.WorkUnitThreadControllerImpl.runExecutionOnThread(WorkUnitThreadControllerImpl.java:90)
at com.ibm.jbatch.container.util.BatchWorkUnit.run(BatchWorkUnit.java:117)
at com.ibm.ws.context.service.serializable.ContextualRunnable.run(ContextualRunnable.java:80)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.ibm.jbatch.container.exception.BatchContainerRuntimeException: java.sql.SQLException: ORA-01002: fetch out of sequence
at com.ibm.jbatch.container.controller.impl.ChunkStepControllerImpl.readItem(ChunkStepControllerImpl.java:354)
at com.ibm.jbatch.container.controller.impl.ChunkStepControllerImpl.readAndProcess(ChunkStepControllerImpl.java:245)
at com.ibm.jbatch.container.controller.impl.ChunkStepControllerImpl.invokeChunk(ChunkStepControllerImpl.java:626)
... 14 more
Caused by: java.sql.SQLException: ORA-01002: fetch out of sequence
我有额外的日志等,如果它们有帮助的话。提前致谢。