title: How to force @Transactional in JPA to commit two repository action not only just the last one?
body: <p>Hi what i trying to achieve is to do &quot;UPDATE&quot; action and then do &quot;DELETE&quot; action with Spring Data JPA and @Transactional annotation, and i want both action is executed but if one of the action is failed, i need a rollback, how do i do this properly?</p>
  <p>first here is my service class :</p>
  <pre><code>@Transactional
  @Service
  public class TransDeliveryPlanningService {
  
      public ResponseRequest&lt;TransDeliveryPlanning&gt; deleteTransDeliveryPlanning(InputDeleteRequest&lt;ViewAndDeleteRequest&gt; request) {
          String currentUser = request.getLoggedInUser();
          String reasonDeleted = request.getReason();
          Long id = request.getObject().getId();
          ResponseRequest&lt;TransDeliveryPlanning&gt; response = new ResponseRequest&lt;TransDeliveryPlanning&gt;();
  
          TransDeliveryPlanning transDeliveryPlanningOld = transDeliveryPlanningRepository.findById(id).orElseThrow(() -&gt; new ResourceNotFound(&quot;Data &quot;+ id +&quot; not found!&quot;));
          transDeliveryPlanningOld.setIsDeleted(true);
          transDeliveryPlanningOld.setReasonDeleted(reasonDeleted);
          transDeliveryPlanningOld.setModifiedBy(currentUser);
          
          TransDeliveryPlanning updatedTransDeliveryPlanning = transDeliveryPlanningRepository.save(transDeliveryPlanningOld);
  
          transDeliveryPlanningRepository.delete(transDeliveryPlanningOld);
  
          //NOTE delete transStuffing
          List&lt;TransStuffing&gt; transStuffing = transStuffingRepository.findBydeliveryPlanningId(transDeliveryPlanningOld.getId());
          Boolean deletePermit = false;
          for(TransStuffing ts : transStuffing) {
              if(ts.getStatus().equalsIgnoreCase(&quot;new&quot;)) {
                  deletePermit = true;
              } else {
                  throw new ResourceIsDelete(&quot;Stuffing &quot; + ts.getStuffingNo() + &quot; Status already changed, delete is not permited!&quot;);
              }
          }
  
          if(deletePermit){
              transStuffingRepository.deleteAll(transStuffing);
          }
  
          //NOTE end of delete transStuffing
  
          if(updatedTransDeliveryPlanning != null) {
              response.setResponse(&quot;Sukses Hapus&quot;);
              response.setObject(updatedTransDeliveryPlanning);
          } else {
              response.setResponse(&quot;Gagal Hapus&quot;);
          }
          
          return response;
      }
  
  }
  </code></pre>
  <p>as you can see, i do <strong><code>transDeliveryPlanningRepository.save</code></strong> and then the next line i do <strong><code>transDeliveryPlanningRepository.delete</code></strong> and the next repo i need to execute is <strong><code>transStuffingRepository.deleteAll</code></strong></p>
  <p>The goal i need to do save before delete is i use Hibernate Audit Envers to create an AuditLog, so i want log the delete reason into my audit table and then delete the record. But when i use <code>**@Transactional**</code>  annotation the <strong><code>transDeliveryPlanningRepository.save</code></strong> (update) not executed, my function just execute <strong><code>transDeliveryPlanningRepository.delete</code></strong> and <strong><code>transStuffingRepository.deleteAll</code></strong> how i keep the save executed with @Transactional annotation?</p>
  <p><em><strong>UPDATE</strong></em></p>
  <p>As Morteza Bandi answer below suggestion, here is my updated code :
  here is my repository :</p>
  <pre><code>@Repository
  public interface TransDeliveryPlanningRepository extends RevisionRepository&lt;TransDeliveryPlanning, Long, Integer&gt;, JpaRepository&lt;TransDeliveryPlanning, Long&gt; {
      
      @Modifying
      TransDeliveryPlanning save(TransDeliveryPlanning transDeliveryPlanning);
  }
  </code></pre>
  <p>when i do this, still it's not update before delete, what did i still miss here?</p>