title: Spring boot integration with spring batch and jpa
body: <p>I am integrating a spring boot project with a spring batch and data jpa project . All stuff related to job and data configuration is right except , persisting my job writer result in database . after I read a file and process it , i can't write it to mysql database . There is no error but no inserting too . interesting thing is my datasource is configured . because before inserting , I can fetch a sample record from database .please assist me to solve this problem.</p>
  
  <p>my application.properties :</p>
  
  <pre><code>spring.datasource.url = jdbc:mysql://localhost:3306/batchtest?  characterEncoding=UTF-8&amp;amp;autoReconnect=true
  spring.datasource.username = root
  spring.datasource.password = root
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  </code></pre>
  
  <p>batch configuration:</p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  public class BatchConfiguration {
  
  @Autowired
  public JobBuilderFactory jobBuilderFactory;
  @Autowired
  public StepBuilderFactory stepBuilderFactory;
  
  @Bean
  public ResourcelessTransactionManager transactionManager() {
      return new ResourcelessTransactionManager();
  }
  
  @Bean
  public JobRepository jobRepository(ResourcelessTransactionManager transactionManager) throws Exception {
      MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean = new MapJobRepositoryFactoryBean(transactionManager);
      mapJobRepositoryFactoryBean.setTransactionManager(transactionManager);
      return mapJobRepositoryFactoryBean.getObject();
  }
  
  @Bean
  public SimpleJobLauncher jobLauncher(JobRepository jobRepository) {
      SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
      simpleJobLauncher.setJobRepository(jobRepository);
      return simpleJobLauncher;
  }
  @Bean
  public FlatFileItemReader&lt;Person&gt; reader() {
      FlatFileItemReader&lt;Person&gt; reader = new FlatFileItemReader&lt;Person&gt;();
      reader.setResource(new ClassPathResource("sample-data.csv"));
      reader.setLineMapper(new DefaultLineMapper&lt;Person&gt;() {{
          setLineTokenizer(new DelimitedLineTokenizer() {{
              setNames(new String[] { "firstName", "lastName" });
          }});
          setFieldSetMapper(new BeanWrapperFieldSetMapper&lt;Person&gt;() {{
              setTargetType(Person.class);
          }});
      }});
      return reader;
  }
  @Bean
  public PersonItemProcessor processor() {
      return new PersonItemProcessor();
  }
  @Bean
  public ItemWriter&lt;Person&gt; writer() throws Exception {
      return new PersonWriter();
  }
  @Bean
  public Job importUserJob() throws Exception{
      return jobBuilderFactory.get("importUserJob")
              .incrementer(new RunIdIncrementer())
              .flow(step1())
              .end()
              .build();
  }
   @Bean
  public Step step1() throws Exception{
      return stepBuilderFactory.get("step1")
              .&lt;Person, Person&gt; chunk(1)
              .reader(reader())
              .processor(processor())
              .writer(writer())
              .build();
  }
  </code></pre>
  
  <p>Dao class :</p>
  
  <pre><code>public interface PersonDao extends CrudRepository&lt;Person,Integer&gt; {
  }
  </code></pre>
  
  <p>writer class :</p>
  
  <pre><code>public class PersonWriter implements ItemWriter&lt;Person&gt; {
  @Autowired
  PersonDao personDao;
  
  @Override
  public void write(List&lt;? extends Person&gt; items) throws Exception {
      LOGGER.info("Received the information of {} students", items.size());
      for(Person person:items)
      {
          LOGGER.info(String.format("inserting for customre %s %s", person.getFirstName(), person.getLastName()));
          Person tempPerson = personDao.findOne(1);
          personDao.save(person) ;
          LOGGER.info(String.format("person id : %d",person.getId()));
      }
  
  }
  </code></pre>
  
  <p>tempPerson is an object for testing the jpa data . it fetches a person object with <strong>id</strong> 1 from database but next line there is no inserting to database with no error. just executing of the line and continue the loop.</p>