0

I have a service like so:

@Service
@Transactional
public myService{

public Flux<entity1> method1(){
// some non flux code
 return Flux.interval().filter().doFinally(MyResponse myRes-> updateDataSource(entity1));
}

public void updateDataSource(entity1){
 MyRepo.save(entity1);
 // code that can throw some exceptions
MyRepo.save(entity2);
}
}

I have a service class annotated with @Transactional. I have a method1() which returns a flux and calls another service method updateDataSource which persists an entity into the DB runs some code that can throw exception and persists a second entity.

My problem is that after persisting entity1 in updateDataSource if an exception is thrown the saved entity1 is not rolled back. In the call stack I cannot see any Transaction manager related proxies/ interceptors even though I'm calling a method which is inside a @Transactional service.

Why is the @Transactional annotation not working with updateDataSource ?

Gestalt
  • 93
  • 10
  • I'm suspecting that this is happening because I'm calling a method in the same bean and it may not be flux related? Can anyone confirm? – Gestalt Apr 16 '23 at 07:17
  • 2
    Indeed, if you invoke a inner method, you will bypass the transactional proxy in front of the service bean. Solutions here: https://stackoverflow.com/questions/3423972/spring-transaction-method-call-by-the-method-within-the-same-class-does-not-wo – TacheDeChoco Apr 16 '23 at 07:32

0 Answers0