Reputation: 1197
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
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