1

I'm using Spring boot 2.1.12 I have a method annontated with @Async and @Transactional and everything works fine

@Asyn
@Transactional
public void doSomeStuff(){
//do some stuff
}

If an exception appears, rollback is done and everithing is done asynchronously.

Now if something fails ( exception) I need to save something in DB so I need that save method is outside the transaction. My solution was call a transactional method inside de @Async method

@Async
public void asynProcess(){
 try {
   doSomeStuffTransaction();
 } catch(Exception ex) {
   saveErrorInDB(ex);
 }
}

@Transactional
public void doSomeStuffTransaction(){
// do some stuff
}

but now the rollback is not executed. The transaction seems to disappear.

Any idea?

thanks in advance

Xavi
  • 87
  • 2
  • 10

0 Answers0