I read the Transactional
documentation and found that NESTED
and REQUIRED
behave very similarly, why is propagation
default value REQUIRED
.
@Serviceclass A { @Autowired private B b; @Transactional public void a() { // ... try { b.b(); } catch (Exception e) { // not throw exception } // ... }}@Serviceclass B { @Transactional public void b() { // do something }}
Consider the above code. Even though I catch
the exception
thrown from b
, a
still rollback. If b
uses NESTED
, then it won't rollback. In this case, the code will look verbose. According to the documentation, we know that they behave similarly, so why?
Execute within a nested transaction if a current transaction exists, behave like REQUIRED otherwise.
UPDATE:
If a throws an exception, I need them both to rollback.