Transactional Annotation on Private Methods
Spring creates proxies when dealing with transactions, when a method is annotated with @Transactional. the proxy intercepts the call, manages the transaction, and then delegates the call to actual method implementations.
The call to private Transaction method is not intercepted by proxy being an internal call, and @Transactional is ignored in this case.
Get Anshu Kulshrestha’s stories in your inbox
Join Medium for free to get updates from this writer.
So there are two ways to handle this
- Make the method public
- Move the logic to another class and call this class
@Service
public class MyService{
@Autowired
private AnotherService anotherService;
public void publicMethod(){
anotherService.privateTransactionalMethod();
}
}
@Service
public class AnotherService{
@Transactional
private void privateTransactionalMethod(){
// code to DB logic
}
}





