I'm using @Transactional in my service 开发者_开发技巧layer. If I annotate two updating service methods with @Transactional (using default settings) and a controller method is calling both of these methods to perform its action, do both service methods use the same transaction?
It appears that they do not, and I am looking for confirmation of this. It would appear to me that to get both methods to use the same transaction I would need to write a third method in the service, annotate it with @Transactional, and call the original two methods from there.
everything you said is correct, including how to get around the issue. It might be a good time to implement a Facade service that coordinates all your other services. That way the the used services will participate in the transactions of the Facade service.
That sounds correct to me. But you should also think whether or not those two methods should have default settings for Transaction propagation. See here and decide if it should be 'REQUIRED' or 'SUPPORTS' ? example: @Transactional(propagation = Propagation.REQUIRED)
精彩评论