4 Replies Latest reply on Apr 14, 2014 4:22 AM by anderruiz

    XTS + JTA + MyBatis-Spring

    anderruiz

      (This message is not answered it was my fault, and I don't know were to change it..)

       

      I'm trying to implement atomic transactions between different WS calls in a WAR file that uses MyBatis-Spring. I'm trying to put all the pieces together but I still don't understand what am I missing.

       

      What I already have

       

      - XTS running

      - A client that creates a UserTransaction, that transaction is available in the WS code

       

      (http-/0.0.0.0:8080-4) UserManagement transaction id =AtomicTransactionIdentifier: urn:0:ffff0a849f13:4142a6d1:533d7738:1c

      - I included context handlers for parsing the new Headers and for trying to connect the transaction to a JTA transaction in JBoss

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- -->
      <handler-chains xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee">
          <handler-chain>
              <protocol-bindings>##SOAP11_HTTP</protocol-bindings>
              <!-- JSR 181 does not seem to directly define how the handler chain is constructed from this xml, although JSR 109
                  6.2.2.3 seems to indicate the parser is required to maintain the declared ordering. JSR 224 9.3.2 says the constructed chain
                  is then invoked in reverse order for inbound requests. Since we need the HeaderContextProcessor to be invoked before the
                  InboundBridgeHandler, we therefore list the InboundBridgeHandler first -->
              <handler>
                  <handler-name>TransactionBridgeHandler</handler-name>
                  <handler-class>org.jboss.jbossts.txbridge.inbound.JaxWSTxInboundBridgeHandler</handler-class>
              </handler>
              <handler>
                  <handler-name>ContextHandler</handler-name>
                  <handler-class>com.arjuna.mw.wst11.service.JaxWSHeaderContextProcessor</handler-class>
              </handler>
          </handler-chain>
      </handler-chains>
      
      
      
      

       

      With the previous configuration, according to my understanding I will have a CMT using JTA right?

       

      - In MyBatis-Spring I tried to configure it to use JTA/CMT transactions also. This is my applicationContext.xml

       

          <bean id="telventDB" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
              p:password="${jdbc.password}" p:url="${jdbc.url}" p:username="${jdbc.username}" />
      
      
          <bean id="wsSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
              <property name="dataSource" ref="telventDB" />
              <property name="typeHandlersPackage" value="com.telvent.tolling.typehandlers" />
          </bean>
      
      
          <!-- enable component scanning -->
          <context:component-scan base-package="com.telvent.tolling" />
      
      
          <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
              <property name="basePackage"
                  value="com.telvent.tolling.tps.mapper;com.telvent.tolling.utility.mapper;com.telvent.tolling.core.wfe.mapper;com.telvent.tolling.vps.mapper;com.telvent.tolling.csc.mapper;com.telvent.tolling.fareschedule.mapper;com.telvent.tolling.tagplate.mapper;com.telvent.tolling.vendor.mapper;com.telvent.tolling.feemanagement.mapper;com.telvent.tolling.shiftmanagement.mapper;com.telvent.tolling.systemparameter.mapper;com.telvent.tolling.core.usermanagement.mapper" />
              <property name="sqlSessionFactoryBeanName" value="wsSqlSessionFactory" />
          </bean>
      
      
          <!-- enable autowire -->
          <context:annotation-config />
          <tx:jta-transaction-manager />
      
      
      
      

       

      I'm testing one insert in the database and one error (without an exception) that the client detects and executes a rollback. Attached the output that I get

       

      Am I missing something obvious?

        • 1. Re: XTS + JTA + MyBatis-Spring
          paul.robinson

          Hello,

           

          I'm not sure how you un-mark it either. Don't worry though, we have seen your post and we'll get back to you shortly.

           

          Paul.

          • 2. Re: XTS + JTA + MyBatis-Spring
            paul.robinson

            Ander,

             

            Can you tell us a bit more about your deployment? It looks like your application is running inside JBoss/Wildfly, can you confirm this? And if so, can you provide the application server version?

             

            Also, are your client and service running in the same server instance, or different instances?

             

            Paul.

            • 3. Re: XTS + JTA + MyBatis-Spring
              anderruiz

              I'm using JBoss 7.2 and both client and service are in the same server instance. One doubt related with that once JaxWSTxInboundBridgeHandler is being used do I need to modify my code for example to implement xxxParticipant or something like this?

              • 4. Re: XTS + JTA + MyBatis-Spring
                anderruiz

                My problem seemed to be that the dataSource I was using in MyBatis was not a standard dataSource for JBoss, therefore it was outside JTA transaction. After using a JBoss datasource seems to be working without problem.

                 

                <?xml version="1.0" encoding="UTF-8"?>
                
                
                <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
                    xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc"
                    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
                    xmlns:jee="http://www.springframework.org/schema/jee"
                    xmlns="http://www.springframework.org/schema/beans"
                    xsi:schemaLocation="
                      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
                   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
                   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
                      http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd">
                    
                    <bean id="wsSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
                        <property name="dataSource" ref="dataSource" />
                        <property name="typeHandlersPackage" value="com.telvent.tolling.typehandlers" />
                        <property name="transactionFactory">
                            <bean class="org.apache.ibatis.transaction.managed.ManagedTransactionFactory" />
                        </property>
                    </bean>
                
                  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
                  <property name="basePackage" value="..." />
                  <property name="sqlSessionFactoryBeanName" value="wsSqlSessionFactory" />
                  </bean>
                
                
                    <!-- enable autowire -->
                    <context:annotation-config />
                    <tx:jta-transaction-manager />
                    <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/DBDS"/>
                </beans>