title: How make repository save synchronized with Spring Boot
body: <p>I have one method that first get the last id from my table by one type. 
  then I set my bean with this number and save</p>
  
  <pre><code>  Long number = geradorProtocoloService.getNumero(protocolo.getTipo()    
    protocolo.setNumber(number);     
    protocolo = protocoloRepository.saveAndFlush(protocolo);
  </code></pre>
  
  <p>I put this code in a synchronized block</p>
  
  <pre><code>synchronized (this) {
    protocolo.setNumero(geradorProtocoloService.getNumero(protocolo.getTipo());
    protocolo = protocoloRepository.saveAndFlush(protocolo);
  }
  </code></pre>
  
  <p>the method have more logic(save a file and etc) then return this to my user</p>
  
  <p>but when I run my tests the he are catching a few times the same number (numero) I think that happens because the jpa don't commit my transaction when I execute saveAndFlush.</p>
  
  <p>So how can I make everything in my synchronizes block be commited with jpa</p>
  
  <p>tks</p>