Announcement Announcement Module
No announcement yet.
DirectChannel : Transaction doesn't rollback Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • DirectChannel : Transaction doesn't rollback

    I'm getting some interesting transaction behavior on Direct Channels. Here's what I'm doing:

    1. Read from a File and write to a Direct Channel.
    2. Start a Chain
    3. Perform Database Operation X - ServiceActivator(@Transactional)
    4. Perform Database Operation Y - ServiceActivator(@Transactional)
    5. End Chain

    I'm just using the default transaction attributes. If Step 4 throws a RuntimeException, it doesn't seem to rollback the database operation performed by Step 3. I can't seem to figure out why that would happen? I appreciate any inputs. Thanks.

    Here's my configuration:
       	<int-file:inbound-channel-adapter id="SOME.ADAPTER.ID"  prevent-duplicates="false" 
    		directory="${EDIFACT.SRC.DIRECTORY}"  scanner="recursiveScanner"
    		channel="SOME.DIRECT.CHANNEL" >
    		<int:poller id="DEFAULT.POLLER" default="true">
    			<int:interval-trigger fixed-rate="true"  interval="${POLL.INTERVAL}" />
    	<int:channel id="SOME.DIRECT.CHANNEL"/>
    	<int:chain input-channel="SOME.DIRECT.CHANNEL" output-channel="SOME.QUEUE.CHANNEL">
    		<int:service-activator ref="fileLockService" method="obtainFileLock"/>
    		<int:service-activator ref="fileLockService" method="test"/>
    	<bean id="transactionManager"
    		<property name="sessionFactory" ref="sessionFactory" />
    	<tx:annotation-driven transaction-manager="transactionManager" />

  • #2
    With that configuration, you have defined two separate transaction scopes; they are independent, as you have discovered.

    If you wish to run the entire flow in a single transaction, you need to start the transaction before entering the <chain/>. One way to do that is to add a

    subelement to the poller subelement of the inbound adapter. Of course, the propagation in your @Transactional services must be REQUIRED (the default), rather than REQUIRES_NEW; otherwise you'll see no difference.
    Last edited by Gary Russell; Aug 28th, 2011, 09:14 PM.


    • #3
      Thank you, Gary. I really appreciate your response. My naive brain thought that anything under the DirectChannel would be "automatically" be part of "one" transaction. I see that the documentation suggests using a transactional element on a poller.