问题
(Assuming manual enlistment and delistment of resources.)
I have a number of XA enabled resources/datasource for which I plan to perform transactional updates. Additionally, some of the XA-enabled datasources can be updated in isolation (without requiring any other resource).
Assuming I have already committed a number of transactions with a datasource enlisted, can I then ignore the TransactionManager for unilateral updates to the datasource.
Do I simply not start a global transaction and commit directly on the resource itself? Assuming this is the correct approach, can I then subsequently enlist the resource in a transaction without side-effect?
Thanks,
Chris
回答1:
XA-resources support XA. Not require. Therefore it is totally possible to start a non-XA transaction over an XA-supporting resource, and commit it locally.
The second question is not quite clear. Add a resource under local transaction into XA transaction? Not sure it is a supported use-case. Or the question is "can I add the resource to an XA transaction after I have committed the local one?". Yes, you can.
Let's take an example of database connection for instance. When a local transaction is started over the connection, the transaction ID exists within the database only. When committed, that ID is gone, and connection is back to the original state, i.e. not within any transaction. Connection can be added to any XA transaction.
Now, when you start an XA transaction, multiple connections (e.g. from different JVMs in a cluster) can share the same transaction ID, and from DB point of view they are within the same transaction. If you have another connection in a local transaction, which has it's own transaction ID for the database, how would you add that connection (and, more importantly, the changes made within it) into the existing XA with a different ID? It would be a messy business, and I believe is not supported.
来源:https://stackoverflow.com/questions/5130934/jta-datasources-without-transactions