Using a XADatasource or Non-XA Data Source for JTA-Based Transactions in JPA

We use JPA 1.0 for ORM-based operations, and we want to have a JTA data source for our application. We have only one database to which our application will connect. We start our transaction boundary in the controller class, and it goes to the DAO → BOImpl → DAO level controller. In the websphere application server administration console, when I define a data source, I must use a data source that is not XA or XA-Datasource.

I understand that for a single data source I should not use XADatasource. Please let me know what I need to use.

+4
source share
2 answers

For one resource (for example, one database) you really do not need a source of XA data.

On the other hand, keep in mind that most JTA / JTS implementations do recognize that only one resource is involved in transactions, so the overhead for XA will be minimal or negligible. There may also be additional participants in transactions that you may not think about now, for example, sending JMS messages.

But if you are really sure that you have only one participating resource, you can safely switch to non-XA.

+2
source

I hope now your doubt can be clear, but just in case, more information about this.

Typical XA resources are databases, messaging tools like JMS or WebSphere MQ, mainframe applications, ERP packages, or something else that can be negotiated with a transaction manager. XA is used to coordinate the so-called two-phase commit (2PC) transaction . A classic example of a 2PC transaction is that two different databases need to be updated atomically. Most people think of something like a bank that has one database for savings accounts and another for checking accounts. If a client wants to transfer money between his checking and savings accounts, both databases must be involved in the transaction, or the bank risks losing some of the money.

The problem is that most developers think: "Well, my application uses only one database, so I do not need to use XA in this database." This may not be true . The question to ask is “ Does the application require shared access to multiple resources that need to ensure the integrity of the transaction being performed? ” For example, does the Java 2 application use connector architecture adapters or Java Message Service (JMS)? If the application needs to update the database and any of these other resources in the same transaction, then both the database and the other resource need to be treated as XA resources.

+1
source

Source: https://habr.com/ru/post/1385929/


All Articles