开发者

Spring @Transactional boundaries

开发者 https://www.devze.com 2023-03-13 02:17 出处:网络
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 me

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号