I have the following scenario. I am using JPA, Spring:
@Autowired
SampleService service;
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Ex
Spring transactions are proxy-based. Here's thus how it works when bean A causes a transactional of bean B. A has in fact a reference to a proxy, which delegates to the bean B. This proxy is the one which starts and commits/rollbacks the transaction:
A ---> proxy ---> B
In your code, a transactional method of A calls another transactional method of A. So Spring can't intercept the call and start a new transaction. It's a regular method call without any proxy involved.
So, if you want a new transaction to start, the method createSampleObject()
should be in another bean, injected into your current bean.
This is explained with more details in the documentation.
My guess is that since both methods are in the same bean, the Spring's AOP does not have a chance to intercept the create/updateSampleObject method calls. Try moving the methods to a separate bean.
Please create a bean for the same class(self) and use bean.api(which requires requires_new). It works.