Thursday 18 October 2018

SOA 12c : How to rollback transaction in BPEL

There are scenarios when we want to complete commit or complete rollback.
This is known as transaction handling.
To demonstrate this scenario I am taking following use case.

Use Case : Read a file and insert data into Header and Line tables. Data must be inserted into both the tables or it should be complete roll back in case of any exception.

Lets start the use case :

1. Drag a file adapter in the Exposed Services. Configure it to read a file from Local directory.


2. Configure two database adapters to insert data into header and line tables.
3. Create a BPEL process and wire it to the FTP adapter and database adapter. After wiring it your composite should look like as below :





















4. Add invoke activity and other assign activity to complete BPEL process. Deploy the service to em console.



















5. For handling transactions you must use a XA datasource. You can create a XA datasource using admin console.

6.  There are two cases for transaction handling.
First Case :

If you are not using catch all, transaction will automatically rollback in case of any exception. In the below example first we will insert data in Header_Details table after that we will try to insert a string value for a column of number type in Line_Details table. It will throw an exception and complete transaction will be rollback.






















Since the transaction was rolled back, it should not insert date Header_Details table and Line_Details table.

























Second Case :

If you are using a catch all, then transaction will not be rolled back automatically in case of any exception. Add a catch all activity in the BPEL service.

BPEL Activity :



















Run the service :























Here transaction was not rolled back, even the BPEL process has been completed.
Let see entries in database tables :































From the above screen shots we can see the transaction was not rolled back. It has inserted data into Header_Details table. But as per our requirement it should not happen. To resolve this issue, you need to use a rethrow activity at the end of your catch all block. In this way control will go back to BPEL and it will handle transaction.


















Run the service :






















The transaction was rolled back, lets see the table entries.











No comments:

Post a Comment

xslt padding with characters call template for left pad and right pad

  Could a call-template be written that took two parameters ?   a string, and a   number) return the string with empty spaces appended t...