When using @Transactionnal with Spring
-
How does it select the datasource on which it should open the transaction?
-
Is there some magic trick like proxies, threadlocals or anything?
-
If so, do these tricks work with any JDBC library (for Hibernate it works but what about MyBatis?)
-
What if there are 2 datasources?
-
And what if i’m calling, in a @Transactionnal service, DAO’s with 2 underlying different datasources? Will it be transactionnal for both datasources or just for one of them or will it fail?
Thanks
To use multiple transaction handlers just specifiy a qualifier, and reference it. For two different DAOs with two different datasources, you’ll need two different transaction managers. And of course the transactions should be going on your service classes, not DAO’s directly. Its the same for any type of transactionmanager be it hibernate or plain old jdbc.
and session factory
and just set up a datasource with the ID dataSourceOne, then you cran reference the transactionmanager in code with the qualifier name :