How to rollback a transaction?
Hi all!
I am using Java CAPS 5.1.1 and trying to figure out how the
transactions work. Can anybody please explain me or send an example
how to rollback the whole business process?
For example in a business process I want to perform two operations
from an Oracle OTD and the second one raises an exception. What should
I do to rollback both of them?
Thanks!
[405 byte] By [
sand123] at [2007-11-26 11:20:34]

# 1
You can configure the entire business process as XA transaction. However I am not aware how to rollback and stuff.
However there is anther way, put both your Oracle OTD operations activity inside a SCOPE element and add a compensationHandler to it. In that compensation handler you can perform activities to rollback you changes. Then add a fault handler to catch any exception and than add a compansate element and name it with name of the SCOPE element to automatically execute compansation handler of the SCOPE.
Thanks
Sanjeev
Sunju at 2007-7-7 3:36:00 >

# 2
Sunju, thank you for your reply.
I tried exactly what you are proposing. I configured whole process as XA transaction and set participate properties of both my oracle invoke activities, but still when I get an exception in my second oracle activity, first one gets commited.
Regarding scopes and compensation handlers, this is not exactly what I need. I wouldn't like to manually delete records, which have been inserted and commited, I prefer rollbacking them. My understanding is that this is a supported scenario, but I don't get how to make this work.
Regards,
Victor
# 3
I was reading more about the XA transaction and it seems that since CAPS is providing a way to configure it as XA transaction and activities to participate in the XA transaction, The commit and rollback should automatically be called in case of exceptions.
Also I can see there is methods like commit and roll back in Oracle OTD.
So hopefully nothing needs to be done as long as Oracle eWay supports XA Global transaction.
Thanks
Sanjeev
Sunju at 2007-7-7 3:36:00 >

# 4
That was also my understanding that exception should result in a rollback. However numerous experiments gave me no hint on how to implement that. No matter what I do, the transaction gets commited. My only achievement is that it is commited atomically, which means that both oracle activities are executed within one transaction and are commited simultaneously, but anyway, commited, never rollbacked.
Regarding commit and rollback methods in OTD, they are only available in JCD, not in business process.
Victor
# 5
What I know for ICAN 5.05, in JCD any unhandled exceptions wil cause a roll back. What we were doing was subscribing an event from the Queue and inserting into DB. If DB is down and unable to be connected, then in the JCD specifically I throw an new exception, but do not catch it. This causes the data to be rolled back to the JMS q.
I am guessing we can try the same logic in from a BP.
Thx
Ravi
# 6
Ravi,
Unfortunately whatever exceptions I throw either from the JCD or using throw activity in BP, the transaction gets commited. That's why I am asking if anybody can send me an example project to look what I am doing wrong. I would suspect that transactional business process behavior should be a popular feature, I am surprised that nobody uses it...
Victor
# 7
There are a number of parts to this and it depends on how you want to do it.
Probably the best way is to use a JCD with an Oracle OTD; in general if the JCD exits abnormally (ie you throw an exception) the transaction should be rolled back. This is true in XA mode, cant remember the model for non-XA mode. Check that you specify XA mode in the CMap between the JCD and the database.
If you use a BP, you can use the "roll-forward" or compensation handler concept from BPEL i.e. create a compensating database update within the handler attached to the containing scope of the second activity you mentioned.
Alternatively, CAPS has a new facility in 5.1 which allows you to set the whole BP into XA mode (accessed via the BP-level properties). Using this has other consequences and is generally used only for short-running process which do not use flows.
# 8
I tried the scenario, where there are two JCDs, called from BP sequentially via JMS. Both have XA attribute set. First one inserts a record into oracle database, second one raises an oracle exception. In CMap a proper XA eWay mode set up. Insert still gets commited.
I would not like to use compensation handlers, because deleting a commited insert is much more expensive than rollbacking. Moreover it breaks the ACID concept of the database... I understand that if I had a long-living transaction, I would have no other option but compensate, but I want to operate short-living transactions.
Java CAPS is stated to support WS-Transaction AT, which I would expect to suite me perfectly. However I can't see a way to make it work.
Thanks,
Victor