0

I read in this link that it is possible to use @Transactional in the service layer

Well, if we have several databases, then it is possible to use a single transaction for all of them? After all, isn't every transaction in each database specific to that database? So how can it be shared among all of them?

AMZ
  • 305
  • 1
  • 5
  • 3
    "*Well, if we have several databases, then it is possible to use a single transaction for all of them?* - This is in general possible, yes. We would, however, have `n+1` transactions for `n` databases (one per database, and one global transaction managed by the global transaction manager, to group them together). But not without additional configuration. The phrase you're looking for are [distributes/global/XA-Transactions (`en.wikipedia.org`)](https://de.wikipedia.org/wiki/X/Open_XA). Whether this, however, is desirable is another question. – Turing85 Jan 20 '23 at 19:01
  • 1
    As an aside: From an architectual point of view, I would recommend to not have `@Transactional` in the service layer. If we have complex persistence logic, I would suggest to write a dedicated DAO to handle this, and the `@Transactional`-annotation would then be placed there. – Turing85 Jan 20 '23 at 19:09

0 Answers0