Author |
Message
|
gappodi |
Posted: Thu Mar 23, 2017 6:23 pm Post subject: Rollback in java compute node |
|
|
 Voyager
Joined: 05 Sep 2014 Posts: 76
|
I have designed a message flow consisting of few standard message broker nodes. In one of the Java compute node, I am obtaining a DB connection using the broker method i.e. getJDBCType4Connection(). I am trying to execute few DML queries like select, insert with in the java compute node.
It is working fine if there does not occur any error/exception and my data base gets updated properly. However, I want to have a mechanism where in if there is any runtime exception thrown in my java compute node at any point, the entire things committed till that point should rollback and no update should be made to the data base.
I tried using conn.setAutoCommit(false) in my code but of no use. Also., I tried to manually invoke rollback() on my connection object in which case I am getting the following error.
An invalid COMMIT or ROLLBACK has been called in an XA environment during a Global Transaction.
Please provide help here. |
|
Back to top |
|
 |
smdavies99 |
Posted: Thu Mar 23, 2017 11:02 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Have you tried using the search feature? {upper right of the screen}
A search for "JDBC XA" might provide you with some help. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Mar 24, 2017 3:36 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
What happens if you thrown an exception out of your JavaCompute node? _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
gappodi |
Posted: Fri Mar 24, 2017 8:07 pm Post subject: |
|
|
 Voyager
Joined: 05 Sep 2014 Posts: 76
|
I tried putting a throw node after my java compute node propagates the message through failure terminal. This still doesn't seem to be rolling back the statements already executed by the java compute node. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Mar 25, 2017 3:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
gappodi wrote: |
I tried putting a throw node after my java compute node propagates the message through failure terminal. This still doesn't seem to be rolling back the statements already executed by the java compute node. |
Have you tried marking the session's status for rollback only? This is different from trying to roll back the session but tells the XA coordinator that it will have to rollback.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Mar 27, 2017 5:11 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You are not, as far as I know, allowed to do anything to control the JDBC transaction inside the JavaCompute node.
You have to set the connection to use XA_AUTO (whatever it's called).
This means that the JDBC transaction is entirely controlled by the transaction of the Message flow.
Trying to catch an exception out of the failure terminal generally doesn't work. It's not an exception there, it's a failure.
If you want to roll back a JDBC transaction, you need to ensure that the entire message flow is rolled back.
To accomplish this, you catch exceptions thrown by your jdbc connection insert statement.
Then you throw those exceptions back out of the javacompute node, so that they will propagate to exception handling at the broker level.
To indicate a failure (and roll back a transaction), issue an exception from the JavaCompute node and the broker will handle the rollback.
https://www.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac30495_.htm#ac30495_
Then any *upstream* catch terminals can process the exception. But jdbc rollback won't occur until you let the input node's exception processing work.
That varies based on the type of input node, but the database rollback should still occur. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
|