javaoracle11gspring-jmsxaatomikos

Atomikos transaction issue with JMS listener and Oracle datasource - XID raised -4: the supplied XID is invalid for this XA resource


I have a web application gathering data from MQ and persist in database. Using spring JMS listener container for reading messages from MQ, and using hibernate template to persist those messages on a XA Oracle datasource. I am englobing transactions on both with JTA transaction manager. I general it works fine, but I am having a randomly occuring issue when trying to persist messages received in my database. Oracle raises an XID invalide exception when trying to persist data, and the whole global transaction rolbacks. The issue is occuring rarely,only 1 in a 100 message. But cant just understand the reason.

I am using MQ client 7.5 Spring 3.1.1.RELEASE Hibernate 3.3.2.GA Atomikos 4.0.6

Below is the full stacktrace for the exception:

    2018-05-23 10:30:32,265 [Atomikos:989] WARN c.a.icatch.imp.ActiveStateHandler - Transaction 10.185.9.141.tm152706422182917585 has timed out and will rollback. 
2018-05-23 10:30:36,194 [jmsContainerLuxembourg-2] WARN  c.a.d.xa.XAResourceTransaction - XA resource 'oracle': resume for XID '31302E3138352E392E3134312E746D313532373036343232313832393137353835:31302E3138352E392E3134312E746D3839' raised -4: the supplied XID is invalid for this XA resource 
oracle.jdbc.xa.OracleXAException: null
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1110)
    at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:240)
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)
    at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:40)
    at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:46)
    at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:70)
    at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:160)
    at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:207)
    at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:122)
    at com.sun.proxy.$Proxy31.prepareStatement(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145)
    at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
    at org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:740)
    at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:737)
    at com.fortis.be.ilms.server.feature.target2.entity.Target2Repository.saveOrUpdate(Target2Repository.java:114)
    at com.fortis.be.ilms.server.feature.target2.Target2ListenerService.checkResponseType(Target2ListenerService.java:110)
    at com.fortis.be.ilms.server.feature.target2.Target2Listener.onMessage(Target2Listener.java:79)
    at com.fortis.be.ilms.server.feature.target2.Target2Listener.onMessage(Target2Listener.java:61)
    at com.fortis.be.ilms.server.feature.target2.Target2JmsListener.onMessage(Target2JmsListener.java:23)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:326)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:244)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960)
    at java.lang.Thread.run(Thread.java:745)
2018-05-23 10:30:36,195 [jmsContainerLuxembourg-2] WARN  c.a.jdbc.JdbcConnectionProxyHelper - Error enlisting in transaction - connection might be broken? Please check the logs for more information... 
com.atomikos.datasource.ResourceException: XA resource 'oracle': resume for XID '31302E3138352E392E3134312E746D313532373036343232313832393137353835:31302E3138352E392E3134312E746D3839' raised -4: the supplied XID is invalid for this XA resource
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:303)
    at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:40)
    at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:46)
    at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:70)
    at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:160)
    at com.sun.proxy.$Proxy31.prepareStatement(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145)
    at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)       at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
    at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:737)
    at com.fortis.be.ilms.server.feature.target2.entity.Target2Repository.saveOrUpdate(Target2Repository.java:114)
    at com.fortis.be.ilms.server.feature.target2.Target2ListenerService.calcMovements(Target2ListenerService.java:418)
    at com.fortis.be.ilms.server.feature.target2.Target2ListenerService.treatReturnTransactionResponse(Target2ListenerService.java:281)
    at com.fortis.be.ilms.server.feature.target2.Target2JmsListener.onMessage(Target2JmsListener.java:23)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:244)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960)
    at java.lang.Thread.run(Thread.java:745)
Caused by: oracle.jdbc.xa.OracleXAException: null
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1110)
    at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:240)
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)
    ... 38 common frames omitted
2018-05-23 10:30:36,195 [jmsContainerLuxembourg-2] ERROR c.f.b.i.s.f.t.Target2JmsListener - Error on treating message from TARGET 2 ! 
com.atomikos.datasource.ResourceException: XA resource 'oracle': resume for XID '31302E3138352E392E3134312E746D313532373036343232313832393137353835:31302E3138352E392E3134312E746D3839' raised -4: the supplied XID is invalid for this XA resource
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:303)
    at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:40)
    at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:46)
    at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:70)
    at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:160)
    at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:207)
    at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:122)
    at com.sun.proxy.$Proxy31.prepareStatement(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:145)
    at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:96)
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:117)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
    at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:535)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:527)
    at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:523)
    at org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:740)
    at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:737)
    at com.fortis.be.ilms.server.feature.target2.entity.Target2Repository.saveOrUpdate(Target2Repository.java:114)
    at com.fortis.be.ilms.server.feature.target2.Target2ListenerService.calcMovements(Target2ListenerService.java:418)
    at com.fortis.be.ilms.server.feature.target2.Target2ListenerService.treatReturnTransactionResponse(Target2ListenerService.java:281)
    at com.fortis.be.ilms.server.feature.target2.Target2ListenerService.checkResponseType(Target2ListenerService.java:110)
    at com.fortis.be.ilms.server.feature.target2.Target2Listener.onMessage(Target2Listener.java:79)
    at com.fortis.be.ilms.server.feature.target2.Target2Listener.onMessage(Target2Listener.java:61)
    at com.fortis.be.ilms.server.feature.target2.Target2JmsListener.onMessage(Target2JmsListener.java:23)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1071)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960)
    at java.lang.Thread.run(Thread.java:745)
Caused by: oracle.jdbc.xa.OracleXAException: null
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1110)
    at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:240)
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)
    ... 38 common frames omitted
2018-05-23 10:30:36,197 [jmsContainerLuxembourg-2] WARN  c.a.d.xa.XAResourceTransaction - XA resource 'oracle': resume for XID '31302E3138352E392E3134312E746D313532373036343232313832393137353835:31302E3138352E392E3134312E746D3839' raised -4: the supplied XID is invalid for this XA resource 
oracle.jdbc.xa.OracleXAException: null
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1110)
    at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:240)
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)
    at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:40)
    at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:46)
    at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:70)
    at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:160)
    at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:207)
    at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:122)
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
    at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2678)
    at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
    at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:145)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1063)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960)
    at java.lang.Thread.run(Thread.java:745)
2018-05-23 10:30:36,197 [jmsContainerLuxembourg-2] WARN  c.a.jdbc.JdbcConnectionProxyHelper - Error enlisting in transaction - connection might be broken? Please check the logs for more information... 
com.atomikos.datasource.ResourceException: XA resource 'oracle': resume for XID '31302E3138352E392E3134312E746D313532373036343232313832393137353835:31302E3138352E392E3134312E746D3839' raised -4: the supplied XID is invalid for this XA resource
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:303)
    at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:160)
    at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:207)
    at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:122)
    at com.sun.proxy.$Proxy31.prepareStatement(Unknown Source)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
    at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2242)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2678)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1063)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960)
    at java.lang.Thread.run(Thread.java:745)
Caused by: oracle.jdbc.xa.OracleXAException: null
    at oracle.jdbc.xa.OracleXAResource.checkError(OracleXAResource.java:1110)
    at oracle.jdbc.xa.client.OracleXAResource.start(OracleXAResource.java:240)
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)
    ... 30 common frames omitted
2018-05-23 10:30:37,229 [jmsContainerLuxembourg-2] WARN  o.s.j.l.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'queue://FRILS01P/BGL.TO.ILMS.RESPONSE.MS5' - trying to recover. Cause: XA resource 'oracle': resume for XID '31302E3138352E392E3134312E746D313532373036343232313832393137353835:31302E3138352E392E3134312E746D3839' raised -4: the supplied XID is invalid for this XA resource 
2018-05-23 10:30:37,231 [jmsContainerLuxembourg-2] INFO  o.s.j.l.DefaultMessageListenerContainer - Successfully refreshed JMS Connection

To give you a detailed idea on my setup, I have a JMS listener container configured via spring xml file as below.

<!-- and this is the message listener container -->
<bean id="jmsContainerLuxembourg" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="mqQueueConnectionFactory"/>
    <property name="destination" ref="jms-destination-target2-luxembourg"/>
    <property name="messageListener" ref="t2messageListener" />
    <property name="transactionManager" ref="transactionManager"/>
</bean>

and below is the configuration of my oracle datasource:

<!-- XA DataSource for target2 services-->      
<bean id="dataSourceTarget" class="com.atomikos.jdbc.AtomikosDataSourceBean" init-method="init" destroy-method="close">
    <property name="uniqueResourceName" value="oracle"/>
    <property name="xaDataSourceClassName"><value>oracle.jdbc.xa.client.OracleXADataSource</value></property>
    <property name="xaProperties">
        <props>
            <prop key="user">${jdbc.username}</prop>
            <prop key="password">${jdbc.password}</prop>
            <prop key="URL">${jdbc.url}</prop>
        </props>
    </property>
    <property name="minPoolSize"><value>1</value></property>
    <property name="maxPoolSize"><value>100</value></property>
    <property name="borrowConnectionTimeout"><value>30</value></property>
    <property name="maxIdleTime"><value>60</value></property>
    <property name="reapTimeout"><value>0</value></property>
    <property name="maintenanceInterval"><value>60</value></property>
</bean>

below is how I link my datasource with Hibernate:

<!-- Atomikos Transaction Configuration START -->
<!-- Hibernate SessionFactory For Target2 Listener Services-->
<bean id="sessionFactoryTarget"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
    p:dataSource-ref="dataSourceTarget">
    <property name="jtaTransactionManager" ref="AtomikosTransactionManager"/>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.generate_statistics">${hibernate.generate_statistics}</prop>
            <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.current_session_context_class">jta</prop>
            <prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
            <prop key="hibernate.transaction.factory_class">com.atomikos.icatch.jta.hibernate3.AtomikosJTATransactionFactory</prop>
        </props>
    </property>
    <property name="packagesToScan">
        <list>
            <value>com.fortis.be.ilms.**</value>
        </list>
    </property>
    <property name="eventListeners">
        <map>
            <entry key="merge">
                <bean
                    class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
            </entry>
        </map>
    </property>
</bean>

<bean id="hibernateTemplateTarget" class="org.springframework.orm.hibernate3.HibernateTemplate">
    <constructor-arg><ref bean="sessionFactoryTarget"/></constructor-arg>
</bean>

And here is how I setup the transaction manager:

<!-- Atomikos Transaction Configuration START -->
    <bean id="userTransactionService" class="com.atomikos.icatch.config.UserTransactionServiceImp" init-method="init" destroy-method="shutdownForce">
        <constructor-arg>
            <!-- IMPORTANT: specify all Atomikos properties here -->
            <props>
                <prop key="com.atomikos.icatch.service">com.atomikos.icatch.standalone.UserTransactionServiceFactory</prop>
                <prop key="com.atomikos.icatch.max_actives">-1</prop>
                <prop key="com.atomikos.icatch.log_base_name">${atomikos.icatch.log_base_name}</prop>
                <prop key="com.atomikos.icatch.output_dir">${atomikos.icatch.output_dir}</prop>
                <prop key="com.atomikos.icatch.log_base_dir">${atomikos.icatch.log_base_dir}</prop>
            </props>
        </constructor-arg>
    </bean>

    <!-- Construct Atomikos UserTransactionManager, needed to configure Spring -->
    <bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
        init-method="init" destroy-method="close" depends-on="userTransactionService">
       <!--  when close is called, should we force transactions to terminate or not? -->
       <property name="forceShutdown" value="false" />
    </bean>

    <!-- Also use Atomikos UserTransactionImp, needed to configure Spring  -->
    <bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp" depends-on="userTransactionService">
       <property name="transactionTimeout" value="300" />
    </bean>

    <!-- Configure the Spring framework to use JTA transactions from Atomikos -->
    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" depends-on="userTransactionService">
       <property name="transactionManager" ref="AtomikosTransactionManager" />
       <property name="userTransaction" ref="AtomikosUserTransaction" />
       <qualifier value="atomikos"/>
    </bean>

Here is my JMS Listener class:

  @Component
@Scope("prototype")
public class Target2JmsListener implements MessageListener {

    private final static Logger logger = Logger.getLogger(Target2JmsListener.class.getName());

    @Autowired Target2Listener listener;

    @Override
    public void onMessage(Message msg) {
        System.out.println("Received message from SIM [" + msg + "]");
        try {
            listener.onMessage(msg);
        } catch (Exception ex) {
            logger.error("Error on treating message from TARGET 2 !", ex);
        }
    }
}

and the DAO that tries to save in DB via hibernate:

@Component
public class Target2Repository {

    private static final Logger LOGGER = Logger.getLogger(Target2Repository.class);

    @Autowired
    private HibernateTemplate hibernateTemplateTarget;

public void saveOrUpdate(Object entity) {
        if (entity instanceof DbTarget2ControlM && Target2Repository.LOGGER.isDebugEnabled()) {
            final DbTarget2ControlM ctrlM = (DbTarget2ControlM) entity;
            Target2Repository.LOGGER.info("Control M is updated with : "
                            + "Msg Id = " + ctrlM.getMsgId()
                            + " Type = " + ctrlM.getMsgType()
                            + " Status = " + ctrlM.getStatus());
        }
        this.hibernateTemplateTarget.saveOrUpdate(entity);
    }
}

Thanks in advance for your help guys


Solution

  • As stated in my comment, putting 'sessionTransacted=true' on my JMS listener container resolved my issue.