title: How to declare `@Transactional` in a Spring Boot service so exception is thrown "immediately"?
body: <p>Say I have the following spring beans in a spring boot app. My intent is to make <code>createFoo()</code> transactional so:</p>
  
  <ol>
  <li>When <code>barService.bar()</code> throws exceptions, the persist gets rolled back.</li>
  <li>When the persist throws exception, the exception propagates up to the caller "immediately" so <strong><code>barService.bar()</code> is NOT called</strong>.</li>
  </ol>
  
  <pre class="lang-java prettyprint-override"><code>@Service
  public class FooService
  {
      @Autowired
      private FooRepository fooRepository;
      @Autowired
      private BarService barService;
  
      @Transactional
      public void createFoo(Foo foo) {
          fooRepository.save(foo);
          // expect to not execute when the above line throws exceptions
          barService.bar();
      }
  }
  
  @Service
  public class BarService {
      public void bar() {
  
      }
  }
  </code></pre>
  
  <p>So far the 1st requirement works, however the 2nd doesn't. When the persist throws exception, <strong><code>barService.bar()</code> is AlWAYS called</strong>.</p>
  
  <p>If I remove <code>@Transactional</code>, 2nd requirement works, the 1st doesn't.</p>
  
  <p>I also tried all <code>Propagation</code> types, none of them work as I expected. For example, if I use <code>@Transactional(MANDATORY)</code>, I get the following error:</p>
  
  <pre><code>org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
  </code></pre>