BizService class, marked as transactional
@Override
@Transactional(rollbackFor = Exception.class)
public void rollbackCredit(List<Order> orderList) {
// omitted biz code
}
TransactionalHelper and Operation class:
public class TransactionalHelper {
@Transactional(
rollbackFor = {Exception.class}
)
public void transactionOperation(final Operation operation) {
operation.execute();
}
}
public interface Operation {
void execute();
}
Now, I write the code as below. Would the code in lambda run in the same transaction?
Or method orderLogRepository.batchInsertSelective(logList)
throw Exception,the data changing in method bizService.rollbackCredit(orderList)
and orderRepository.batchUpdateOptional(orderList, "orderStatusCode")
would be persisted in the database?
transactionalHelper.transactionOperation(() -> {
// call service method with @Transactional
bizService.rollbackCredit(orderList);
// db operation
orderRepository.batchUpdateOptional(orderList, "orderStatusCode");
// db operation
orderLogRepository.batchInsertSelective(logList);
});