title: Rollback Spring Transaction after network failure
body: <p>I'm working on rather simple RESTful service based on SpringBoot. I'm using Ebean and SpringData. All my REST methods are annotated with @Transactional:</p>
  
  <pre><code>@Transactional
  @PostMapping
  public Entity createEntity(...) {
     // some code
  }
  </code></pre>
  
  <p>The problem I'm facing is that if there is a network issue but this method executes without an exception, the transaction will still get committed. For example, the client might send the data, my code creates the record but then the server can't send a response back to the client. In this case, I'd want the transaction to rollback but I didn't find a way of doing that.</p>
  
  <p>Is it even possible to rollback the transaction in this case? Maybe there is a Spring platform limitation I'm overlooking.</p>
  
  <p>Thanks</p>
  
  <p>EDIT: To answer the replies below and specify the question further: It's easy enough to rollback the transaction. The tricky part is to run any code in response to the network failure. I was hoping that I can configure Spring to do it for me. Like "wait until you sent the last byte and then rollback or commit the transaction". My current code will commit the transaction as soon as the createEntity() method has finished.</p>