Spring Boot: Transaction silently rolled back because it has been marked as rollback-only

Viewed 8336

I am trying to save exception message in DB table in Catch block but the Exception Transaction is also getting rolled back when the code passes the whole @Transactional method.

Ex:

@javax.transaction.Transactional
public void operationMethod(){
 serviceMethod();
}

public void serviceMethod()
 try{
 }
 catch(Exception e){
saveException(e.getMessage());
}
}

//here tried @org.springframework.transaction.annotation.Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = Exception.class) and different combinations with Nested and Required
saveException(String exceptionMessage){
//save it into table logic
}

Still it is giving the "Transaction silently rolled back because it has been marked as rollback-only" exception. Is there any way to force commit only saveException part without save try block and rolling back exception save.

Thanks in Advance

0 Answers
Related