spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Method invocation skipped when @Scheduled components are invoking @Transactional methods

Open sbchaud opened this issue 4 years ago • 2 comments

It seems that when we are trying to call @Transactional methods from @Scheduled methods, the calls simply do not occur.
The @Transactional methods work totally fine when they are being invoked from @Controller REST endpoints within our application.

I wrote two classes like below...

`Component public class StartActionTransactionHelper {

Autowired
 ActionRepository repo;

Transactional
public Mono<Void> startAction() {
   repo.doAction().subscribe();

   return null;
}

} `

`Component public class StartActionScheduler {

Autowired
StartActionTransactionHelper startActionTransactionHelper;

Scheduled(fixedDelay = 1000)
public void startActions() {
    startActionTransactionHelper.startAction();
}

}`

If I remove @Transactional, then the code gets invoked, but without being in a Transaction.

sbchaud avatar Nov 08 '21 16:11 sbchaud

Found a workaround to use TransactionalOperator operator and as(operator::transactional) as below...

Reference is https://github.com/hantsy/spring-r2dbc-sample/blob/master/docs/database-client.md.

However, the fact that @Transactional does not work, I think is still an issue.

sbchaud avatar Nov 09 '21 03:11 sbchaud

Returning null instead of Mono<Void> feels strange. It's impossible for caller to know when method execution is finished without a Mono to subscribe for

gumanoid avatar Jul 28 '22 21:07 gumanoid

That and startActions looks really odd to me.

@sbchaud rather than code in text, please share a small sample that we can run ourselves to reproduce the issue. You can do so by attaching a zip to this issue or push the code to a separate GitHub repository.

snicoll avatar Oct 02 '23 09:10 snicoll

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Oct 09 '23 09:10 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar Oct 16 '23 09:10 spring-projects-issues