title: JPARepository is not saving to DB
body: <p>Long story, but I had to redesign an application this weekend. From a spring boot app to a spring batch app. The process was always a batch process, but I tried to make this batch engine and it got way too complex and i had to stop what I was doing. I'm sure we've all been there. Anyway everything is working fine!! Except for one piece of code that I tried to keep the original piece of code for. I'm trying to use a JPARepository save method and it's not working!! I am able to call the save method, I feel like the Repo is instantiated because I'm not getting a null pointer exception. In fact, I'm not getting any exceptions thrown. I am just not seeing anything in the DB. And I know this code has worked because I had it running in the previous design. Anyway here are my classes...</p>
  <p>Data object:</p>
  <pre><code>@Data
  @Entity
  @Table(name=&quot;PAYEE_QUAL_LS&quot;)
  public class PayeeList {
  
      @EmbeddedId
      private PayeeListPK payeeListPK = new PayeeListPK();
      @Column(name = &quot;PAYEE_QUAL_CD&quot;)
      private String payeeQualCode;
      @Column(name = &quot;ETL_TS&quot;)
      private Timestamp etlTimestamp;
  }
  </code></pre>
  <p>Primary key data class...</p>
  <pre><code>@Data
  @Embeddable
  public class PayeeListPK implements Serializable {
  
      @Column(name = &quot;PAYEE_NM&quot;)
      private String payeeName;
      @Column(name = &quot;BAT_PROC_DT&quot;)
      private Date batchProcDate;
  }
  </code></pre>
  <p>Repo class...</p>
  <pre><code>@Repository
  public interface PayeeListRepo extends JpaRepository&lt;PayeeList,String&gt; {}
  </code></pre>
  <p>My Service class...</p>
  <pre><code>public class OracleService {
      private static final Logger logger = LoggerFactory.getLogger(OracleService.class);
  
      @Autowired
      PayeeListRepo payeeListRepo;
  
      public void loadToPayeeListTable(PayeeList payeeList) {
          payeeListRepo.save(payeeList);
      }
  </code></pre>
  <p>I have an implementation of Tasklet which I am calling from my batch Step...</p>
  <pre><code>public class PayeeListTableLoad implements Tasklet {
      private static final Logger logger = LoggerFactory.getLogger(PayeeListTableLoad.class);
  
      private java.sql.Date procDt;
      private String inputFile;
      private Timestamp time;
      private int safeRecordCount = 0;
      private int blockRecordCount = 0;
      private int safeRejectRecordCount = 0;
      private int blockRejectRecordCount = 0;
      private ArrayList&lt;String&gt; rejectRecordList = new ArrayList&lt;&gt;();
  
      @Autowired
      OracleService oracleService;
  
      @Override
      public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
          SimpleDateFormat format = new SimpleDateFormat(&quot;yyyyMMdd&quot;);
          java.util.Date parsed = format.parse(System.getenv(&quot;procDt&quot;));
          procDt = new java.sql.Date(parsed.getTime());
          inputFile = Constants.filePath;
          time = new Timestamp(System.currentTimeMillis());
  
          logger.info(&quot;Running data quality checks on input file and loading to Oracle&quot;);
  
          try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) {
              String line = reader.readLine();
              while (line != null) {
                  if (dataQuality(line)) {
                      PayeeList payeeList = buildPayeeListObject(line);
                      oracleService.loadToPayeeListTable(payeeList);
                      logger.info(&quot;Record loaded: &quot; + line);
                  } else {
                      rejectRecordList.add(line);
                      try {
                          if (line.split(&quot;\\|&quot;)[1].equals(&quot;B&quot;)) {
                              blockRejectRecordCount++;
                          } else if (line.split(&quot;\\|&quot;)[1].equals(&quot;S&quot;)) {
                              safeRejectRecordCount++;
                          }
                          logger.info(&quot;Record rejected: &quot; + line);
                      } catch (ArrayIndexOutOfBoundsException e) {
                          e.printStackTrace();
                      }
                  }
                  line = reader.readLine();
              }
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          logger.info(&quot;Safe record count is: &quot; + safeRecordCount);
          logger.info(&quot;Block record count is: &quot; + blockRecordCount);
          logger.info(&quot;Rejected records are: &quot; + rejectRecordList);
  
          SendEmail sendEmail = new SendEmail();
          sendEmail.sendEmail(Constants.aegisCheckInclearingRecipient,Constants.aegisCheckInclearingSender,Constants.payeeListFileSuccessEmailSubject,Constants.payeeListFileSuccessEmailBodyBuilder(safeRecordCount,blockRecordCount,safeRejectRecordCount,blockRejectRecordCount,rejectRecordList));
  
          logger.info(&quot;Successfully loaded to Oracle and sent out Email to stakeholders&quot;);
  
          return null;
      }
  </code></pre>
  <p>In my batch configuration....</p>
  <pre><code>    @Bean
      public OracleService oracleService() { return new OracleService(); }
  
      @Bean
      public PayeeListTableLoad payeeListTableLoad() {
          return new PayeeListTableLoad();
      }
  
      @Bean
      public Step payeeListLoadStep() {
          return stepBuilderFactory.get(&quot;payeeListLoadStep&quot;)
                  .tasklet(payeeListTableLoad())
                  .build();
      }
  
      @Bean
      public Job loadPositivePayFile(NotificationListener listener, Step positivePayLoadStep) {
          return jobBuilderFactory.get(&quot;loadPositivePayFile&quot;)
                  .incrementer(new RunIdIncrementer())
                  .listener(listener)
                  .start(positivePayDataQualityStep())
                  .next(initialCleanUpStep())
                  .next(positivePayLoadStep)
                  .next(metadataTableLoadStep())
                  .next(cleanUpGOSStep())
                  .build();
      }
  </code></pre>
  <p>Ultimately our step is running an implementation of Tasklet, we are Autowiring out OracleService class, and then that is being called and is then calling the Repo method. I am getting to the Oracle Service class method and I am calling the save method of my Autowired Repository but again nothing is happening!!</p>
  <p><strong>EDIT!!!</strong></p>
  <p>I have figured out another way to do it and that is with EntityManager and using the persist and flush methods. Below is now my loadToPayeeListTable method in my Oracle Service class...</p>
  <pre><code>    public void loadToPayeeListTable(PayeeList payeeList) throws ParseException {
          EntityManager entityManager = entityManagerFactory.createEntityManager();
          EntityTransaction transaction = entityManager.getTransaction();
          transaction.begin();
          entityManager.persist(payeeList);
          entityManager.flush();
          transaction.commit();
          entityManager.close();
      }
  </code></pre>