title: spring batch with spring boot using RepositoryItemReader nativeQuery
body: <p>Presently i am using Spring boot + Spring batch  + Spring data jpa.</p>
  
  <p>i am using RepositoryItemReader. with normal </p>
  
  <pre><code>    Page&lt;QuoteOfferFulfillment&gt; findByStatus(String status,
                      Pageable pageable);
  </code></pre>
  
  <p>its working fine and working as expected. but when i have use Native queries i am not getting any error but always results are coming 0. i have tried both ways:</p>
  
  <pre><code>    1. 
  
      @Query(value = "SELECT * FROM QUOTE_OFFER_FULFILLMENT QOF WHERE QOF.STATUS= (:status) OR QOF.STATUS=(:status1) AND QOF.RETRY_COUNT &lt; 3 \n#pageable\n", countQuery = "SELECT count(*) FROM QUOTE_OFFER_FULFILLMENT QOF WHERE QOF.STATUS=(:status) OR QOF.STATUS=(:status1) AND QOF.RETRY_COUNT &lt; 3 \n#pageable\n", nativeQuery = true)
          Page&lt;QuoteOfferFulfillment&gt; findByStatusAndRetryCount(
                  @Param("status") String status,
                  @Param("status1") String status1, Pageable pageable);
  
  and second way
  
      2. Page&lt;QuoteOfferFulfillment&gt; findByStatusAndRetryCount(
                  @Param("status") QuoteOfferFulfillmentStatus status,
                  @Param("status1") QuoteOfferFulfillmentStatus status1, Pageable pageable);
  </code></pre>
  
  <p>in the Entity Class</p>
  
  <pre><code>    @SqlResultSetMappings({
              @SqlResultSetMapping(name = "SqlResultSetMapping.count", columns = @ColumnResult(name = "cnt")) })
      @NamedNativeQueries({
              @NamedNativeQuery(name = "QuoteOfferFulfillment.findByStatusAndRetryCount", resultClass = QuoteOfferFulfillment.class, query = "SELECT * FROM QUOTE_OFFER_FULFILLMENT WHERE STATUS= (:status) OR STATUS=(:status1) AND RETRY_COUNT &lt; 3"),
              @NamedNativeQuery(name = "QuoteOfferFulfillment.findByStatusAndRetryCount.count", resultSetMapping = "SqlResultSetMapping.count", query = "SELECT count(*) as cnt FROM QUOTE_OFFER_FULFILLMENT WHERE STATUS= (:status) OR STATUS=(:status1) AND RETRY_COUNT &lt; 3") })
      @Entity
  
      public class QuoteOfferFulfillment implements Serializable {
  </code></pre>
  
  <p>Other Batch Configuration </p>
  
  <pre><code>    @Configuration
      public class BatchScheduler {
  
          @Bean
          public ResourcelessTransactionManager resourcelessTransactionManager() {
              return new ResourcelessTransactionManager();
          }
  
          @Bean
          public JobRepository jobRepository() throws Exception {
              return new MapJobRepositoryFactoryBean(resourcelessTransactionManager()).getObject();
          }
  
          @Bean
          public ThreadPoolTaskExecutor taskExecutor() {
              ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
              taskExecutor.setCorePoolSize(15);
              taskExecutor.setMaxPoolSize(20);
              taskExecutor.setQueueCapacity(30);
              return taskExecutor;
          }
  
          @Bean
          public SimpleJobLauncher jobLauncher(ThreadPoolTaskExecutor taskExecutor,
                  JobRepository jobRepository) {
              SimpleJobLauncher launcher = new SimpleJobLauncher();
              launcher.setTaskExecutor(taskExecutor);
              launcher.setJobRepository(jobRepository);
              return launcher;
          }
  
      }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    @Configuration
      @EnableBatchProcessing
      @Import(BatchScheduler.class)
      public class BatchConfiguration {
  
      @Autowired
          public StepBuilderFactory stepBuilderFactory;
  
          @Autowired
          public JobBuilderFactory jobBuilderFactory;
  
          @Autowired
          public QuoteOfferFulfillmentRepository fulfillmentRepository;
  
          @Autowired
          private SimpleJobLauncher jobLauncher;
  
      @Scheduled(cron = "*/5 * * * * *")
          public void perform() throws Exception {
  
              System.out.println("Job Started at :" + new Date());
  
              JobParameters param = new JobParametersBuilder()
                      .addString("JobID", String.valueOf(System.currentTimeMillis())).toJobParameters();
  
              JobExecution execution = jobLauncher.run(job(), param);
  
              System.out.println("Job finished with status :" + execution.getStatus());
          }
  
       @Bean
          public RepositoryMetadata repositoryMetadata() {
              return new DefaultRepositoryMetadata(QuoteOfferFulfillmentRepository.class);
          }
  
          @Bean
          public RepositoryItemReader&lt;QuoteOfferFulfillment&gt; reader() {
              RepositoryItemReader&lt;QuoteOfferFulfillment&gt; fullfillment = new RepositoryItemReader&lt;QuoteOfferFulfillment&gt;();
              fullfillment.setRepository(fulfillmentRepository);
              fullfillment.setMethodName("findByStatusAndRetryCount");
              List&lt;QuoteOfferFulfillmentStatus&gt; list = new ArrayList&lt;QuoteOfferFulfillmentStatus&gt;();
              list.add("FULFILLMENT_READY");
              list.add("FAILED");
              fullfillment.setArguments(list);
              fullfillment.setPageSize(40);
              HashMap&lt;String, Direction&gt; sorts = new HashMap&lt;&gt;();
              sorts.put("id", Direction.DESC);
              fullfillment.setSort(sorts);
              return fullfillment;
          }
  
          @Bean
          public RepositoryItemWriter&lt;QuoteOfferFulfillment&gt; writer() {
              System.out.println("BatchConfiguration.writer()");
              RepositoryItemWriter&lt;QuoteOfferFulfillment&gt; itemWriter = new RepositoryItemWriter&lt;QuoteOfferFulfillment&gt;();
              itemWriter.setRepository(fulfillmentRepository);
              itemWriter.setMethodName("save");
              return itemWriter;
          }
  
          @Bean
          public Step step1() throws Exception {
              return this.stepBuilderFactory.get("step1")
                      .&lt;QuoteOfferFulfillment, QuoteOfferFulfillment&gt; chunk(1).reader(reader())
                      .processor(new SubmitionProcessor()).writer(writer()).build();
          }
  
          @Bean
          public Job job() throws Exception {
              System.out.println("BatchConfiguration2.job() =+&gt; ");
              return this.jobBuilderFactory.get("job").incrementer(new RunIdIncrementer()).start(step1())
                      .listener(new JobCompletionListener()).build();
  
          }
  
      }
  </code></pre>
  
  <p>Where would be the wrong i have done. Kindly let me know your suggestions to go forward.</p>