Skip to main content

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.

For more details to configure a FTP adapter, please go through my previous block :

http://exploreofm.blogspot.in/2015/09/soa-12c-how-to-read-file-using-file.html

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.














This way you can handle transactions in BPEL.

Comments

Popular posts from this blog

Difference between OSB 11g And OSB 12c

In this blog I will walk  you  through from the new features of OSB 12c as well as the difference between OSB 11g and 12c. Following are the differences between OSB 11g and 12c : In the new version Oracle Service Bus (OSB) is renamed as Service Bus. Eclipse tool is needed to develop an interface in OSB 11g where as JDeveloper tool is needed to develop an interface in OSB 12c.  Oracle has integrated OSB 12c with JDeveloper. Now there is no need of Eclipse to develop an interface in 12c. Graphical representation of OSB components are similar to SOA BPEL components. Pipeline is separated from proxy service and it is separate component in 12c. To perform operations on database, ftp and files, it is no longer required to configure adapters in JDeveloper and copy it to Eclipse, because OSB 12c service is developed using JDeveloper only.

How to generate a unique id in XSLT

In this post I will explain you how to generate a unique Id in XSLT. To Generate a unique id in XSLT use oraext:generate-guid() function. See below screen shot to generate unique id in XSLT : Result of XSLT : The function oraext:generate-guid() has generated a unique Id as 2d333136303937343532313436323038. Similarly for each run this function will generate different unique Ids.

Oracle SOA Suite12/OSB 12c/JDeveloper Step by step Installation

In this post I will explain you how to install Oracle SOA Suite 12c. Download latest version of SOA 12c from oracle OTN. Download java 7 and install it to your machine If you don't have java 7 installed, your can download it from below path http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html The further installation is shown in Windows OS. You need to create a JAVA_HOME environment variable. Follow the below path to set JAVA_HOME : Click on Advanced System Settings, go to Advance tab and click on  Environment Variables. Click on New under User Variables. Click ok and Save it. Now java 1.7 has been setup in your machine. We are ready to install JDeveloper 12c. Unzip fmw_12.1.3.0.0_soaqs_Disk1_1of1.zip file which you have downloaded from OTN. Now open a command prompt as a administrator Navigate to the installation folder and run command " %JAVA_HOME%\bin\java -jar fmw_12.1...