How to set up Spring Boot + Bitronix + non-XA Datasource + XA JMS Connection - spring

I'm trying to set-up Bitronix in Spring Boot to use last resource gambit with non-XA datasource. Of course by default (autoconfiguration) data source does not participate in XA transaction.
It seems that org.springframework.boot.jta.XADataSourceWrapper will work only for XADataSource.
How to connect DataSource with Bitronix?

Bitronix uses its LrcXADataSource to implement the last resource gambit. You need to tell Spring Boot to create an XAResource of that type:
spring.datasource.xa.data-source-class-name=bitronix.tm.resource.jdbc.lrc.LrcXADataSource
You'll also need to set some other properties that will depend on the database you're using and how it's configured. For example, the name of the JDBC driver class:
spring.datasource.xa.properties.driver-class-name=org.hsqldb.jdbcDriver

Related

Is JTA recommended with Hibernate in Springboot

I have to use hibernate along with spring boot. Is it recommended to use JTA transaction manager in this stack?
If JTA is recommended, how to access current session programmatically in controller or service layer ? with example will be more helpful.
As spring documentation says:
Typically, you need an application server’s JTA capability only if your application needs to handle transactions across multiple resources, which is not a requirement for many applications.
And according to spring boot documentation:
Spring Boot supports distributed JTA transactions across multiple XA resources by using either an Atomikos or Bitronix embedded transaction manager. JTA transactions are also supported when deploying to a suitable Java EE Application Server.
When a JTA environment is detected, Spring’s JtaTransactionManager is used to manage transactions. Auto-configured JMS, DataSource, and JPA beans are upgraded to support XA transactions. You can use standard Spring idioms, such as #Transactional, to participate in a distributed transaction.
As for your second question you can have a look at this answer.

Which transaction manger to be used in Spring JPA Eclipselink with JTA enabled

I'm using Spring 4.0, EclipseLink 2.6.3 with JPA 2.0 and IBM Websphere 8.5.5.8 with JTA enabled (Oracle 11g).
As of now my app is configured with WebSphereUowTransactionManager as my server/ container is Websphere like below.
<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"></bean>
When I was referring to this link from spring doc's in the 8.9.1. Use of the wrong transaction manager for a specific DataSource section it says
If you are using global transactions, you must use the Spring
org.springframework.transaction.jta.JtaTransactionManager for all your
for all your transactional operations. Otherwise Spring will attempt
to perform local transactions on resources such as container
DataSources.
What does it mean ? Should I shift to org.springframework.transaction.jta.JtaTransactionManager as I'm using Spring #Transactional attributes in my services and DAO's ? Please advice.
UPDATE
As mentioned by #JBNizet its a super class extend by different vendor specific Transaction managers.In that case when should I use org.springframework.orm.jpa.JpaTransactionManager ? How is it different from others ?

Spring Boot JMS only transactions support

I'm writing a service and I need to use transactions for JDBC & JMS but not distributed.Is it possible use Spring #Transactional annotation on JMS Listener method for a JMS only Transacion using Bitronix or Atomikos since these 2 are also autoconfigured by Spring ?
As far as I know, when I add this dependency, my dataBase transaction also became XA.
What are my options ?
Please see the boot documentation about Mixing XA and non-XA JMS connections.

Some people say you can handle any global(XA) transaction with Spring + hibernate, true or not?

Some people say you can handle any global transaction with Spring + hibernate, true or not?
Other people say you also need an application server XA datasource or another XA JTA implementation like atomikos or JbossTS or Bitronix.
Which people are correct?
A)spring + hibernate
B)spring + hibernate + another XA JTA implementation?
Neither Spring nor Hibernate comes with an XA-enabled transaction manager. So you indeed need such a transaction manager in order to have distributed transactions with Spring/Hibernate.
This is explained in the Spring documentation.

Can I use Atomikos with Apache DBCP

As the name suggests, can I use Atomikos JTA Transaction Manager with Apache DBCP?
If so, how should I configure it? I'm using Spring & Hibernate.
I'm trying to switch to JTA for transaction management.
Yes you can use it. Atomikos provides a wrapper data source that should be used to wrap the DBCP dataSource. Your database & jdbc driver should support XA.
And then the usual spring configuration to setup a jta transaction manager.
This link has the detailed instructions and configuration.
http://www.atomikos.com/Documentation/SpringIntegration

Resources