EDIT: This only happens with MSSQL & jtds 1.2.6 Still investigating…
**Duplicate of : Mule 3.3.0 Jdbc Transaction Undesired Commit
**Mule Documentation sucks.
I want to rollback everything inside a flow that has several database endpoints.
I have a single JDBC datasource resource (i.e. no need for fancy XA, 2PC, etc).
I have managed to configure Mule to, at least, not complain that no Transaction Manager is configured, etc…. but: It doesn’t work; i.e it does not rollback the transaction when an exception occurs.
Since I’m running Mule standalone, I don’t have fancy weblogic, jboss, etc transactionmanagers so I thought I could use Spring’s DataSourceTransactionManager. What other choice I have for this?
Here is my flow (flow1 is just for triggering flow2, wich is the one I want to be transactional):

And the XML:
<?xml version="1.0" encoding="UTF-8"?>
<mule version="CE-3.3.0">
<spring:beans>
<spring:bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<spring:property name="dataSource" ref="dataSource" />
</spring:bean>
<spring:bean id="transactionFactory"
class="org.mule.module.spring.transaction.SpringTransactionFactory">
<spring:property name="manager" ref="transactionManager" />
</spring:bean>
<spring:bean id="dataSource" name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<spring:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<spring:property name="url" value="jdbc:mysql://localhost/mydb"/>
<spring:property name="username" value="sa"/>
<spring:property name="password" value=""/>
</spring:bean>
</spring:beans>
<jdbc:connector name="jdbcConnector" dataSource-ref="dataSource"
transactionPerMessage="true" queryTimeout="20000" pollingFrequency="10000"
doc:name="Database" validateConnections="false"></jdbc:connector>
<flow name="flow1" doc:name="flow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<vm:outbound-endpoint exchange-pattern="request-response" path="toFlow2" doc:name="VM"/>
</flow>
<flow name="flow2" doc:name="flow2">
<vm:inbound-endpoint exchange-pattern="request-response" path="toFlow2" doc:name="VM">
<custom-transaction factory-ref="transactionFactory" action="ALWAYS_BEGIN" timeout="10"/>
</vm:inbound-endpoint>
<jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="query1" queryTimeout="-1" connector-ref="jdbcConnector" doc:name="Database">
<jdbc:query key="query1" value="insert into Foo (field1) values ('bar')"/>
<jdbc:transaction action="ALWAYS_JOIN"/>
</jdbc:outbound-endpoint>
<jdbc:outbound-endpoint exchange-pattern="request-response" queryKey="query2" queryTimeout="-1" connector-ref="jdbcConnector" doc:name="Database">
<jdbc:query key="query2" value="insert into Bar (field1) values ('foo')"/>
<jdbc:transaction action="ALWAYS_JOIN"/>
</jdbc:outbound-endpoint>
</flow>
</mule>
Not shown here, I also have a default exception catch strategy, that simply writes the faulty payload to a file. I don’t know if I need to do a rollback explicitly, but I didn’t find how.
Any help would be much appreciated.
After two days of banging my head against Mule I finally managed to make this work.
Conclusions:
The final working flow: