Announcement Announcement Module
Collapse
No announcement yet.
How to Specify Local vs. distributed transaction in Spring Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X