title: Spring Data Jpa Save and SaveAndFlush
body: <p>I'm using (Spring Data) <em>JpaRepository</em> to perform CURD operation. Here I saw two methods <em>save</em> and <em>saveAndFlush</em>. in both methods I got the same result, it successfully save data in the database. So what is the difference? I'm not using any sort of transactions mechanism, to issues commit command with the <em>save</em> method.</p>
  
  <pre><code>@Transactional
  public BaseDto add(BulkPermitCategoryDto requestDto) {
      BaseDto baseDto = new BaseDto();
      try {
          BulkPermitCategory category = ObjectConverter
                  .bulkPermitCategoryDtoToBulkPermitCategory(requestDto);
          bulkPermitCategoryRepository.saveAndFlush(category);
          baseDto.setStatusCode(0);
  
      } catch (Exception e) {
          log.error("exception occered ", e);
          e.printStackTrace();
      }
  
      return baseDto;
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Transactional
  public BaseDto add(BulkPermitCategoryDto requestDto) {
      BaseDto baseDto = new BaseDto();
      try {
          BulkPermitCategory category = ObjectConverter
                  .bulkPermitCategoryDtoToBulkPermitCategory(requestDto);
          bulkPermitCategoryRepository.save(category);
          baseDto.setStatusCode(0);
  
      } catch (Exception e) {
          log.error("exception occered ", e);
          e.printStackTrace();
      }
  
      return baseDto;
  }
  </code></pre>