Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring @Transactional boundaries

Tags:

java

spring

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.

like image 589
GriffeyDog Avatar asked Jun 15 '11 20:06

GriffeyDog


1 Answers

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.

like image 63
hvgotcodes Avatar answered Nov 09 '22 18:11

hvgotcodes