title: Spring boot batch Spring data jpa
body: <p>i am using Spring boot + Spring Batch + JPA + Mysql. below are the follow i am following:</p>
  
  <ol>
  <li>spring boot application</li>
  </ol>
  
  <p>```</p>
  
  <pre><code>@SpringBootApplication(scanBasePackages = "com.xxx.xxxx.config, com.xxx.xxx.rest, com.xxx.xxx.domain, com.xxx.xxx.dataservice, com.xxx.xxx.batchconfiguration, com.xxx.xxx.steps")
      @EnableAutoConfiguration
      @EnableConfigurationProperties(Properties.class)
      @EnableEncryptableProperties
      public class SampleApplication
      {
          public static void main(String[] args) {
              SpringApplication.run(SampleApplication.class, args);
          }
  
  
      } 
  </code></pre>
  
  <p>```    </p>
  
  <ol start="2">
  <li>Created @Entity classes based on table structure</li>
  <li>created reposity interface like below</li>
  </ol>
  
  <p>```</p>
  
  <pre><code>@Component
  public interface ExampleRepository extends JpaRepository&lt;tableClass, Long&gt; {
     Page&lt;tableClass&gt; findTop10ByStatus(tableClassStatus status,
              Pageable pageable);
  }
  </code></pre>
  
  <p>```</p>
  
  <ol start="4">
  <li>Batch configuration:</li>
  </ol>
  
  <p>```</p>
  
  <pre><code>@Configuration
      @EnableScheduling
      public class BatchScheduler {
  
          @Bean
          public ResourcelessTransactionManager transactionManager() {
              return new ResourcelessTransactionManager();
          }
  
          @Bean
          public JobExplorer jobExplorer() throws Exception {
              MapJobExplorerFactoryBean jobExplorerFactory = new MapJobExplorerFactoryBean(
                      mapJobRepositoryFactory());
              jobExplorerFactory.afterPropertiesSet();
              return jobExplorerFactory.getObject();
          }
  
          @Bean
          public MapJobRepositoryFactoryBean mapJobRepositoryFactory() throws Exception {
              MapJobRepositoryFactoryBean factory = new MapJobRepositoryFactoryBean();
              factory.setTransactionManager(transactionManager());
              return factory;
          }
  
          @Bean
          public JobRepository jobRepository() throws Exception {
              return mapJobRepositoryFactory().getObject();
          }
  
          @Bean
          public JobLauncher jobLauncher() throws Exception {
              SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
              simpleJobLauncher.setJobRepository(jobRepository());
              return simpleJobLauncher;
          }
  
      }
  </code></pre>
  
  <p>```</p>
  
  <ol start="5">
  <li>batch configuration</li>
  </ol>
  
  <p>```</p>
  
  <pre><code>@Configuration
      @EnableBatchProcessing
      @Import({ BatchScheduler.class })
      public class BatchConfiguration2 {
  
          @Autowired
          public StepBuilderFactory stepBuilderFactory;
  
          @Autowired
          public JobBuilderFactory jobBuilderFactory;
  
          @Autowired
          private SimpleJobLauncher jobLauncher;
  
          @Autowired
          public ExampleRepository exampleRepository ;
  
          @Scheduled(cron = "0/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(ExampleRepository.class);
          }
  
          @Bean
          public RepositoryItemReader&lt;tableClass&gt; reader() {
              RepositoryItemReader&lt;tableClass&gt; fullfillment = new RepositoryItemReader&lt;tableClass&gt;();
              fullfillment.setRepository(ExampleRepository);
              fullfillment.setMethodName("findTop10ByStatus");
              List&lt;tableClassStatus&gt; list = new ArrayList&lt;tableClassStatus&gt;();
              list.add(tableClassStatus.FULFILLMENT_READY);
              fullfillment.setArguments(list);
              HashMap&lt;String, Sort.Direction&gt; sorts = new HashMap&lt;&gt;();
              sorts.put("id", Direction.DESC);
              fullfillment.setSort(sorts);
              return fullfillment;
          }
  
          /* @Bean
          public RepositoryItemWriter&lt;tableClass&gt; writer() {
              System.out.println("BatchConfiguration.writer()");
              RepositoryItemWriter&lt;tableClass&gt; itemWriter = new RepositoryItemWriter&lt;tableClass&gt;();
              itemWriter.setRepository(ExampleRepository);
              itemWriter.setMethodName("save");
              return itemWriter;
          }*/
  
          @Bean
          public RepositoryItemWriter&lt;tableClass&gt; writer() {
              System.out.println("BatchConfiguration.writer()");
              DefaultCrudMethods defaultCrudMethods = new DefaultCrudMethods(repositoryMetadata());
              RepositoryItemWriter&lt;tableClass&gt; itemWriter = new RepositoryItemWriter&lt;tableClass&gt;();
              itemWriter.setRepository(ExampleRepository);
              itemWriter.setMethodName(defaultCrudMethods.getSaveMethod().getName());
              return itemWriter;
          }
  
          @Bean
          public Step step1() throws Exception {
              return this.stepBuilderFactory.get("step1")
                      .&lt;tableClass, tableClass&gt; chunk(1).reader(reader())
                      .processor(new QuoteOfferFullfillmentSubmitionProcessor()).writer(writer()).build();
          }
  
  
          @Bean
          public Job job() throws Exception {
  
              return this.jobBuilderFactory.get("job").incrementer(new RunIdIncrementer()).start(step1())
                      .listener(new JobCompletionListener()).build();
  
          }
  
      }
  </code></pre>
  
  <p>```</p>
  
  <ol start="6">
  <li>QuoteOfferFullfillmentSubmitionProcessor.java</li>
  </ol>
  
  <p>``` </p>
  
  <pre><code>public class QuoteOfferFullfillmentSubmitionProcessor implements ItemProcessor&lt;QuoteOfferFulfillment, QuoteOfferFulfillment&gt; {
  
          @Override
          public tableClass process(tableClass item) throws Exception {
  
              System.out.println("Processor.process() ==&gt; ID " + item.getId());
              System.out.println("Processor.process() ==&gt; " + item.getLenderName());
              System.out.println(
                      "QuoteOfferFullfillmentSubmitionProcessor.process() ==&gt; source" + item.getStatus());
              item.setStatus(QuoteOfferFulfillmentStatus.PROCESSING);
              return item;
          }
  
      }
  </code></pre>
  
  <p>```</p>
  
  <ol start="7">
  <li>JobCompletionListener.java</li>
  </ol>
  
  <p>``` </p>
  
  <pre><code>public class JobCompletionListener extends JobExecutionListenerSupport {
              @Override
              public void afterJob(JobExecution jobExecution) {
                  if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
                      System.out.println("BATCH JOB COMPLETED SUCCESSFULLY");
                  }
              }
  
          }
  </code></pre>
  
  <p>```</p>
  
  <p>after all configuration, running the application every 5 sec the job is running fine, getting values and printing in process class, after that coming to writer class and printing all the values with out Errors. </p>
  
  <p><strong>the problem is: its not updating the values in the Database in write method.</strong> </p>
  
  <p><strong>with out BatchScheduler, scheduler and job launcher  (commit the code) restarting the spring boot its all updating the values in database.</strong></p>
  
  <p>Can you guys suggest me what wrong i am doing.</p>