java - Spring @Transactional how to "stop" transaction -


i have controller calls method on service class should following:

  1. update database (using dao 1)
  2. update database (using dao 2)
  3. sendemail (using email service)

(1) , (2) should atomic , if both succeed email should sent. if annotate service method @transactional email sent if db updates fail (and not desired). furthermore if email fails db update rolled (which not desired either).

my understanding moving 3. separate method on same service class not help. annotating sendemail method @transactional , different propagation behavior (e.g. never or requires_new) not seem either.

is possible achieve behavior proper annotations?

you need have transaction 2 first steps, have transaction committed, , send email. easiest way introduce additional bean

controller:

beana.process(); 

bean a:

// not transactional public void process() {     beanb.updatedatabase();     sendemail(); }  private void sendemail() {     ... } 

bean b:

@transactional public void updatedatabase() {     dao1.update();     dao2.update(); } 

Comments