1
votes

I'm trying to enable JTA with spring boot so that JPA and JMS will roll back together. All docs point to http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html and it states

When a JTA environment is detected, Spring’s JtaTransactionManager will be used to manage transactions.

What is meant by "JTA environment is detected"?

I ask because I think that is what is tripping me up. I added dependencies for Atomikos, but jmsTemplate.isSessionTransacted() returns false. I am assuming I haven't properly marked my environment as JTA. I'm running with embedded tomcat.

What I am experiencing is the database changes are being rolledback with the transaction, but not the JMS messages.

UPDATE:

The part about sessionTransacted was not related. It was my misunderstanding.

2

2 Answers

1
votes

A JTA environment is detected when a supported transaction manager is on the classpath (Atomikos or Bitronix in 1.3, and also Narayana in 1.4) or because a javax.transaction.TransactionManager is available in JNDI (typically because you've deployed your Boot app to a Java EE container).

I think you have misunderstood the purpose of the sessionTransacted flag on JmsTemplate. It's used when creating a new session (Connection.createSession), however the transacted value that's passed to createSession is ignored when you're running in a JTA environment.

1
votes

You can see it in the class org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration:

@ConditionalOnClass(javax.transaction.Transaction.class)
@ConditionalOnProperty(prefix = "spring.jta", value = "enabled", matchIfMissing = true)
@AutoConfigureBefore({ XADataSourceAutoConfiguration.class,
        ActiveMQAutoConfiguration.class, HornetQAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class })
@Import({ JndiJtaConfiguration.class, BitronixJtaConfiguration.class,
        AtomikosJtaConfiguration.class, NarayanaJtaConfiguration.class })
@EnableConfigurationProperties(JtaProperties.class)
public class JtaAutoConfiguration {

}

Basically you have to have the JTA API on the classpath, and at least one JTA provider (Bitronix or Atomikos, if you're not using an application server).