title: Spring batch jpaPagingItemReader why some rows are not read?
body: <p>I 'm using Spring Batch(3.0.1.RELEASE) / JPA  and an HSQLBD server database.
  I need to browse an entire table (using paging) and update items (one by one). So I used a jpaPagingItemReader. But when I run the job I can see that some rows are skipped, and the number of skipped rows  is equal to the page size. For i.e. if my table has 12 rows and the jpaPagingItemReader.pagesize = 3  the job will read : lines 1,2,3 then lines 7,8,9  (so skip the lines 4,5,6)…
  Could you tell me what is wrong in my code/configuration, or maybe it's an issue with HSQLDB paging?
  Below is my code:</p>
  
  <p><strong>[EDIT]</strong> : The problem is with my ItemProcessor that performs modification to the  POJOs Entities. Since JPAPagingItemReader made a flush between each reading, the Entities  are updated ((this is what I want) . But it seems that the cursor paging is also incremented (as can be seen in the log: row ID 4, 5 and 6 have been skipped). How can I manage this issue ?</p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing(modular=true)
  public class AppBatchConfig {
    @Inject
    private InfrastructureConfiguration infrastructureConfiguration;  
    @Inject private JobBuilderFactory jobs;
    @Inject private StepBuilderFactory steps;
  
    @Bean  public Job job() {
       return jobs.get("Myjob1").start(step1()).build();
    }
    @Bean  public Step step1() {  
        return steps.get("step1")
                  .&lt;SNUserPerCampaign, SNUserPerCampaign&gt; chunk(0)
                  .reader(reader()).processor(processor()).build();   
    }
    @Bean(destroyMethod = "")
  @JobScope 
  public ItemStreamReader&lt;SNUserPerCampaign&gt; reader() String trigramme) {
      JpaPagingItemReader reader = new JpaPagingItemReader();
      reader.setEntityManagerFactory(infrastructureConfiguration.getEntityManagerFactory());
      reader.setQueryString("select t from SNUserPerCampaign t where t.isactive=true");
      reader.setPageSize(3));
      return reader;
  }
   @Bean @JobScope
   public ItemProcessor&lt;SNUserPerCampaign, SNUserPerCampaign&gt; processor() {   
       return new MyItemProcessor();
   }
  }
  
  @Configuration
  @EnableBatchProcessing
  public class StandaloneInfrastructureConfiguration implements InfrastructureConfiguration {
   @Inject private EntityManagerFactory emf;  
   @Override
  public EntityManagerFactory getEntityManagerFactory() {
      return emf;
  }
  }  
  </code></pre>
  
  <p>from my ItemProcessor:</p>
  
  <pre><code>@Override
  public SNUserPerCampaign process(SNUserPerCampaign item) throws Exception {
      //do some stuff …
     //then if (condition) update the Entity pojo :   
     item.setModificationDate(new Timestamp(System.currentTimeMillis());
     item.setIsactive = false;
  
  }
  </code></pre>
  
  <p>from Spring xml config file:</p>
  
  <pre><code>&lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;     
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver" /&gt;
      &lt;property name="url" value="jdbc:hsqldb:hsql://localhost:9001/MYAppDB" /&gt;
      &lt;property name="username" value="sa" /&gt;
      &lt;property name="password" value="" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>trace/log summarized :</p>
  
  <pre><code>11:16:05.728 TRACE MyItemProcessor - item processed: snUserInternalId=1]
  11:16:06.038 TRACE MyItemProcessor - item processed: snUserInternalId=2]
  11:16:06.350 TRACE MyItemProcessor - item processed: snUserInternalId=3]
  
  11:16:06.674 DEBUG SQL- update SNUSER_CAMPAIGN  set ...etc...
  11:16:06.677 DEBUG SQL- update SNUSER_CAMPAIGN  set ...etc...
  11:16:06.679 DEBUG SQL- update SNUSER_CAMPAIGN  set ...etc...
  
  11:16:06.681 DEBUG SQL- select ...etc... from  SNUSER_CAMPAIGN snuserperc0_ 
  
  11:16:06.687 TRACE MyItemProcessor - item processed: snUserInternalId=7]
  11:16:06.998 TRACE MyItemProcessor - item processed: snUserInternalId=8]
  11:16:07.314 TRACE MyItemProcessor - item processed: snUserInternalId=9]
  </code></pre>