Quantcast
Channel: Active questions tagged propagation - Stack Overflow
Viewing all articles
Browse latest Browse all 52

Why the default value of spring transactional propagation is `REQUIRED` instead of `NESTED`

$
0
0

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.


Viewing all articles
Browse latest Browse all 52

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>