You have two choices about the type of DataSource, XADataSource or non-XADataSource. See the following differences.

An XA transaction can be defined as a global transaction because it can work on multiple resources. Unlike the XA transaction, a non-XA transaction always works on one resource.

An XA transaction works on a transaction manager that coordinates one or more databases (or different resources, such as JMS) all inside one global transaction. Non-XA transactions often called local transactions also don’t need a transaction coordinator because a single resource makes all transactions work itself.

The X/Open group specification defines the XA transactions on distributed and global transactions. Java Transaction API (JTA) supports this specification, in a form adapted to Java and DataSources.

XA transactions are not often used but they are very important when you must coordinate more resources at the same time. You could need to coordinate two or more databases more than just one connection or other JCA resources altogether. If one of these resources fails by some accident, all the operations come back with a rollback, otherwise, the commit will update all resources.

The protocol used by the Transaction Manager coordinator that we have described is called Two Phase Commit or 2PC. It’s important this protocol also is supported by the individual resources as the databases and other external resources, else the 2PC doesn’t work.

An XA DataSource is a particular DataSource that participates in an XA global transaction. WildFly supports it through Ironjacamar, the official JCA resource adapter implementation and Narayana, the transaction manager implementation in WildFly. A non-XA DataSource can’t participate in a global transaction because it will not be read by the transaction manager coordinator.

Xa resource is used where there is a distributed transaction is required. According to my knowledge XA drivers are used for global transactions and non-XA drivers are used for local transactions.

XA: it’s basically when you have to use a two-phase commit , An XA transaction, in the most general terms, is a “global transaction” that may span multiple resources.

So this would mean for eg if there are two DB that needs to be committed at the same time so in this case, you would use an XA driver.

connection Pool

The reason for using a connection pool is opening and maintaining a database connection for each user, especially requests made to a dynamic database-driven website application, is costly and wastes resources. So to avoid this the connection pool uses a cache of database connections maintained so that the connections can be reused when future requests to the database are required.

XA

An XA transaction, in the most general terms, is a “global transaction” that may span multiple resources. An XA transaction involves a coordinating transaction manager, with one or more databases (or other resources, like JMS) all involved in a single global transaction.

XA transactions come from the X/Open group specification on distributed, global transactions. JTA includes the X/Open XA spec, in modified form.

XA gets involved when you want to work with multiple resources – 2 or more databases, a database and a JMS connection, all of those plus maybe a JCA resource – all in a single transaction. In this scenario, you’ll have an app server like Websphere or Weblogic or JBoss acting as the Transaction Manager, and your various resources (Oracle, Sybase, IBM MQ JMS, SAP, whatever) acting as transaction resources. Your code can then update/delete/publish/whatever across the many resources. When you say “commit”, the results are committed across all of the resources. When you say “rollback”, _everything_ is rolled back across all resources.

The Transaction Manager coordinates all of this through a protocol called Two-Phase Commit (2PC). This protocol also has to be supported by individual resources.

In terms of data sources, an XA datasource is a data source that can participate in an XA global transaction.

NON-XA

A non-XA transaction always involves just one resource. Non-XA transactions have no transaction coordinator, and a single resource is doing all its transaction work itself (this is sometimes called local transactions).

Most stuff in the world is non-XA – a Servlet or EJB or plain old JDBC in a Java application talking to a single database.

A non-XA datasource generally can’t participate in a global transaction (sort of – some people implement what’s called a “last participant” optimization that can let you do this for exactly one non-XA item).

An XA transaction, in the most general terms, is a “global transaction” that may span multiple resources. A non-XA transaction always involves just one resource.

An XA transaction involves a coordinating transaction manager, with one or more databases (or other resources, like JMS) all involved in a single global transaction. Non-XA transactions have no transaction coordinator, and a single resource is doing all its transaction work itself (this is sometimes called local transactions).

Most of the time we use non-XA – a Servlet or EJB or plain old JDBC in a Java application talking to a single database. XA gets involved when you want to work with multiple resources – 2 or more databases, a database and a JMS connection, all of those plus maybe a JCA resource – all in a single transaction. Here, Weblogic will be acting as the Transaction Manager, and your various resources (Oracle, Sybase, IBM MQ JMS, SAP, whatever) acting as transaction resources. Your code can then update/delete/publish/whatever across the many resources. When you say “commit”, the results are committed across all of the resources. When you say “rollback”, _everything_ is rolled back across all resources.

The Transaction Manager coordinates all of this through a protocol called Two Phase Commit (2PC). This protocol also has to be supported by the individual resources.

In terms of datasources, an XA datasource is a data source that can participate in an XA global transaction. A non-XA datasource generally can’t participate in a global transaction (sort of – some people implement what’s called a “last participant” optimization that can let you do this for exactly one non-XA item).