Results 1 to 3 of 3

Thread: Spring managed transaction vs EJB transaction (CMT or BMT)

  1. #1
    Join Date
    Sep 2005
    Location
    Hong Kong, China
    Posts
    33

    Default Spring managed transaction vs EJB transaction (CMT or BMT)

    Hi.. I have been working on Spring managed transaction without problem. I used a DataSourceTransactionManager for all the iBATIS DAOs:

    Code:
        <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" singleton="true">
        	<property name="jndiName">
        		<value>jdbc/DB</value>
        	</property>
        </bean>
    
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource"><ref bean="dataSource"/></property>
        </bean>
    and a TransactionProxyFactoryBean for all the service:

    Code:
    	<bean id="txProxyTemplate" abstract="true"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref bean="transactionManager" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
    			</props>
    		</property>
    	</bean>
    All operation within a service used the same transaction and rollback correctly if necessary.

    However, when I put the service in a SLSB, things go wrong. Shown below is the scenario:

    1) MDB (CMT,Supported)
    1.1) Service A (using the same "txProxyTemplate" configuration as shown above)
    1.1.1) do an update in database by Service B (and iBATIS DAO B)
    1.1.2) SLSB C (CMT,Supported)
    1.1.2.1) Service C (using the same "txProxyTemplate confiruation too)
    1.1.2.1.1) Got error and throw a checked Exception
    1.1.2) catch the checked Exception but the database update operation didn't rollback

    I tried to fixed the problem by using JtaTransactionManager:

    Code:
      <bean id="transactionManager"
        class="org.springframework.transaction.jta.JtaTransactionManager">
      </bean>
    This time, the database update operation was rollbacked. However, instead of throwing the checked Exception, a javax.transaction.TransactionRolledbackException exception was thrown by SLSB C. Does anyone know how to configurate Spring and SLSB property to successfully propagate transaction between them?

    I am using Spring 1.2.2 and WebLogic Server 8.1

    Thanks.

    Koala Lam

  2. #2
    Join Date
    Sep 2005
    Location
    Hong Kong, China
    Posts
    33

    Default

    I found the following in the Spring manual (for v1.2.2, Ch7.5, p85):

    Spring does not support propagation of transaction contexts across remote calls, as do high-end application
    servers. If you need this feature, we recommend that you use EJB. However, don't use this feature lightly.
    Normally we don't want transactions to span remote calls.
    Doesn't it mean the feature I am looking for is not supported by Spring? However, from other posts about transaction, I could find someone saying if JtaTransactionManager is used, EJB transaction will be participated automatically if there exists one. Could somebody help me? Thanks.

    Regards,
    Koala Lam

  3. #3
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    The paragraph you are referring to is about client-controlled transactions. This means starting and closing transactions from a remote client explicitly.
    Spring does only support server-controlled transactions. These could be distributed, however.

    Regards,
    Andreas

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. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 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
  •