Results 1 to 2 of 2

Thread: How to Specify Local vs. distributed transaction in Spring

  1. #1
    Join Date
    Nov 2004
    Posts
    15

    Default How to Specify Local vs. distributed transaction in Spring

    How do I inform Spring to use local transaction if I have only one datasource and distributed transaction if more than one datasource are involved? From the book "J2EE Without EJB" looks like this is an advantage for Spring vs. J2EE container as J2EE container always use 2-phase commit even for a single data source. I am using Hibernate, thus HibernateTransactionManager as my transaction manager. Any help would be greatly appreciated.

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    This is a matter of configuration:
    Local transactions
    Code:
      <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
        <property name="sessionFactory">
          <ref local="sessionFactory"/>
        </property>
      </bean>
    JTA transactions
    Code:
    	<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
    and of course you use both of them the same way:
    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="insert*">PROPAGATION_REQUIRED</prop>
    				<prop key="update*">PROPAGATION_REQUIRED</prop>
    				<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. spring + distributed transaction
    By saurabh in forum Data
    Replies: 1
    Last Post: Oct 10th, 2005, 06:59 AM
  3. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  4. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 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
  •