Announcement Announcement Module
Collapse
No announcement yet.
How to turn off Auto-commit for JTA Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to turn off Auto-commit for JTA

    I've written a simple web app, which I based off of the sample Spring/iBatis JPetstore application.

    When I use a DataSourceTransactionManager, everything works as expected. But when I use JtaTransactionManager, it seems that autocommit is enabled. Individual SQL statements are being committed before the business transaction is completed.

    Any ideas what's causing this? Not sure if this is relevant, but I'm running the app in the embedded OC4J container that gets launched from Oracle JDeveloper 10g.

    Relevant context configuration files are shown below.

    Thanks in advance !!

    Steve

    ------------------------------------------------------------------------------------
    dataAccessContext-local.xml (uses DataSourceTransactionManager)
    ------------------------------------------------------------------------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>

    <!-- ========= RESOURCE DEFINITIONS ========= -->

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName"><value>${jdbc.driverClassNa me}</value></property>
    <property name="url"><value>${jdbc.url}</value></property>
    <property name="username"><value>${jdbc.username}</value></property>
    <property name="password"><value>${jdbc.password}</value></property>
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref local="dataSource"/></property>
    </bean>

    <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation"><value>WEB-INF/sql-map-config.xml</value></property>
    </bean>

    <!-- ==== DAO DEFINITIONS: IBATIS IMPLEMENTATIONS ==== -->

    <bean id="accountingPeriodDao" class="nz.ac.otago.its.chargeadmin.dao.ibatis.SqlM apAccountingPeriodDao">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    <bean id="chargeDao" class="nz.ac.otago.its.chargeadmin.dao.ibatis.SqlM apChargeDao">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    [etc]

    </beans>


    ------------------------------------------------------------------------------------
    dataAccessContext-jta.xml (uses JtaTransactionManager)
    ------------------------------------------------------------------------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>

    <!-- ========= RESOURCE DEFINITIONS ============ -->

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName"><value>jdbc/itsdevPooledDS</value></property>
    </bean>

    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager"/>

    <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClient FactoryBean">
    <property name="configLocation"><value>WEB-INF/sql-map-config.xml</value></property>
    </bean>

    <!-- ==== DAO DEFINITIONS: IBATIS IMPLEMENTATIONS ==== -->

    <bean id="accountingPeriodDao" class="nz.ac.otago.its.chargeadmin.dao.ibatis.SqlM apAccountingPeriodDao">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    <bean id="chargeDao" class="nz.ac.otago.its.chargeadmin.dao.ibatis.SqlM apChargeDao">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="sqlMapClient"><ref local="sqlMapClient"/></property>
    </bean>

    [etc]

    </beans>

    -----------------------------------------------------------------------------
    applicationContext.xml
    -----------------------------------------------------------------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>

    <!-- ========== GENERAL DEFINITIONS ========== -->

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>WEB-INF/mail.properties</value>
    <value>WEB-INF/jdbc.properties</value>
    </list>
    </property>
    </bean>


    <!-- ======== BUSINESS OBJECT DEFINITIONS ======= -->

    <bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean"
    abstract="true">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="transactionAttributes">
    <props>
    <prop key="insert*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>

    <!-- primary business object -->
    <bean id="chargeAdmin" parent="baseTransactionProxy">
    <property name="target">
    <bean class="nz.ac.otago.its.chargeadmin.domain.logic.Ch argeAdminImpl">
    <property name="accountingPeriodDao"><ref bean="accountingPeriodDao"/></property>
    <property name="chargeDao"><ref bean="chargeDao"/></property>
    [etc]
    </bean>
    </property>
    </bean>

    </beans>

  • #2
    The Spring config looks fine. So I would double check the configuration of that datasource in the server. Is it a JTA-enabled datasource?

    Comment


    • #3
      AutoCommit=false and org.apache.commons.dbcp.BasicDataSource

      I am facing the reverse effect while using the almost identical configuration as posted by stevecnz using DataSourceTransactionManager.

      With defaultAutoCommit=false and defaultTransactionIsolation=TRANSACTION_SERIALIZAB LE none of my transactions are being committed. All DB updates are being rolled back without any trace in any of the logs.

      I am having the following settings...
      Code:
      	<bean id="dataSourceHD" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      		<property name="driverClassName"><value>$&#123;jdbc.driverClassName&#125;</value></property>
      		<property name="url"><value>$&#123;jdbc.url&#125;</value></property>
      		<property name="username"><value>$&#123;jdbc.username&#125;</value></property>
      		<property name="password"><value>$&#123;jdbc.password&#125;</value></property>		
      		<property name="defaultCatalog"><value>$&#123;jdbc.defaultCatalog&#125;</value></property>
      		<property name="defaultAutoCommit"><value>$&#123;jdbc.defaultAutoCommit&#125;</value></property>
      		<property name="defaultTransactionIsolation"><value>$&#123;jdbc.defaultTransactionIsolation&#125;</value></property>
      		<property name="validationQuery"><value>$&#123;jdbc.validationQuery&#125;</value></property>		
      	</bean>
      The BusinessObject methods are wrapped around by TransactionProxy as defined below.

      Code:
      	<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
      		<property name="transactionManager"><ref bean="transactionManager"/></property>
      		<property name="transactionAttributes">
      			<props>
      				<prop key="create*">PROPAGATION_REQUIRED</prop>
      				<prop key="insert*">PROPAGATION_REQUIRED</prop>
      				<prop key="update*">PROPAGATION_REQUIRED</prop>
      				<prop key="delete*">PROPAGATION_REQUIRED</prop>
      				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
      			</props>
      		</property>
      	</bean>
      It would be extremely helpful if anybody explains the cause behind.[/code]

      Comment

      Working...
      X