Results 1 to 3 of 3

Thread: How to turn off Auto-commit for JTA

  1. #1
    Join Date
    Sep 2004
    Posts
    9

    Default 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. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    The Spring config looks fine. So I would double check the configuration of that datasource in the server. Is it a JTA-enabled datasource?
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Jul 2005
    Location
    Kolkata, India
    Posts
    4

    Default 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]
    Chandra.

Similar Threads

  1. Connection closed after transaction commit
    By alirussi in forum Data
    Replies: 4
    Last Post: Dec 17th, 2011, 06:41 AM
  2. Can't get JTA transactions to commit
    By Ed_Ward in forum Data
    Replies: 7
    Last Post: Jun 13th, 2006, 09:49 AM
  3. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  4. Replies: 2
    Last Post: Sep 4th, 2005, 06:41 AM
  5. Replies: 3
    Last Post: Aug 4th, 2005, 01:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •