user739115
user739115

Reputation: 1197

How to rollback transaction in camel route

When I throw a RuntimeException in Impl class then the transaction is not getting rolled back. But when I uncomment update statement in Impl class and comment the update statement code in the route then transaction is rolled back.

How to rollback the update statement that is written in the route when implementation class throws exception.

<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="wsRoute">    
<from uri="cxf:bean:paymentServiceEndpoint"/>

<transacted />
 <split streaming="true" parallelProcessing="true"> 
   <simple>${in.body[0]}</simple> 
     <setHeader headerName="bank">
        <simple>${body.bank}</simple>
     </setHeader>
     <log message="The header value is ${header.bank}" />

     <setBody>
        <constant>
                UPDATE TEST 
                SET RECEIVED_BY = 'Y' 
                  WHERE ID = :?bank
        </constant>
      </setBody>
        <to uri="jdbc:dataSource?useHeadersAsParameters=true" /> 

 </split> 
 <bean ref="paymentServiceImpl" />
  <log message="response = ${body}"/>
</route>
</camelContext>

@Transactional(value="txManager", propagation=Propagation.REQUIRED, rollbackFor=Exception.class)
public TransferResponse transfer(TransferRequest request) {
    System.out.println("***********PaymentServiceImpl..." + request.getFrom());
    /*
     final int updated= jdbc.update("update TEST set RECEIVED_BY = 'Y' where ID = ?", 
             "abc" );
     */
    TransferResponse response = new TransferResponse();

    if(true)
    throw new RuntimeException("update exception");

    response.setReply("OK");
    System.out.println("***********PaymentServiceImpl.." + response.getReply());
    return response;
}

Upvotes: 0

Views: 2179

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55555

You cannot use parallel processing with transactions, as the unit of work for the transaction must be done by the same thread, which is required by the transaction manager to orchestrate this correctly. So turn that off.

Upvotes: 1

Related Questions