Search code examples
javaconnection-poolingjtahikaricpatomikos

What are the relationships between JTA provider like Atomikos and connection pool like HikariCP?


I'm reading Java Persistence with Hibernate, and I found the following text.

Today, high-quality standalone JTA providers such as Bitronix (used for the example code of this book) and Atomikos are available and easy to install in any Java environment. Think of these solutions as JTA-enabled database connection pools.

As I understand, JTA providers have their own connection pools.

So, do they integrate (how, if they do) with connection pools like HikariCP and C3P0? Thank you.


Solution

  • The answer is NO, you cannot combine JTA provider with these JDBC Connection Pools.

    The short reason is: The JTA provider need XADataSource and the JDBC Connection Pools named by you just have standard DataSource.

    The longer reason is: With a JTA provider you want to handle global transactions - global means over different DataSources. (e.g. your operation wants to do something in database/DataSource 1 and something in database/DataSource 2 - if one of these parts fail, you want both parts to get rolled back as if nothing has happened to both databases/DataSources) This is done by Two-Phase-Commit and this needs a XADataSource. Your JDBC connection pools are lightweight for applications using only one DataSource - for this applications you do not need JTA (even if you can use them either, of course).