In terms of the difference between the JTA and JTS behaviour, remember that the behavior of the XAResources that are enlisted with the transaction are further restricted by the status' available in the OTS specification .
What that means in practical terms is that there is an additional "stage" separating an XAResource from the transaction coordinator. It is worth noting that the way that Narayana is implemented means that this step is applicable whether the resource is enlisted in the same address space, distributed or of course from a heterogeneous environment to ensure consistency in behavior of the JTS/OTS.
In real terms this means that to remain compliant with JTS/OTS the return codes from an XAResource must be translated into those that are available at the various methods defined in the OTS spec. If you look at section 2.8.2 of the resource interface (I will include here):
void rollback () raises (HeuristicCommit, HeuristicMixed, HeuristicHazard);
You can see that unlike the more verbose options available from xa_rollback (chapter 5, XA ) there are limited options to return in the case of failure of a resource. In the case of RMFAIL on a prepared transaction that leads to us determining this must be dealt with as a heuristic given the more limited options available.
I do hope this clarifies why JTS/OTS has altered the behavior here, if this is not so please do ask for further clarification,
 TRANS 1.4
1 of 1 people found this helpful
Ondřej Chaloupka wrote:
I do understand that the OTS specification differs from local JTA case but I would like *understand* why it behaves differently. I've been a bit searching in the code of Narayana and it took me to this doubt.
If I compare the jta XAResourceRecord  with jts XAResourceRecord  at the same time when JTA version returns FINISH_ERROR the JTS throws HeuristicHazard exception (for first prepared xa resource). Why the same situation ends with HeuristicHazard for JTS and there is no special care for JTA (in meaning that recovery manager can fix the situation on his own afterwards). In speech of code why the JTS prepared xa resource can't just throw UNKNOWN() exception  and ends with FINISH_ERROR ?
Remark: The code for the JTS case is running in a different JVM from the where the coordinator runs so we return the result using methods defined by the OTS resource (ie either an OTS exception or a Vote). In the JTA case the coordinator drives the resource via the XAResource interface (I say this to indicate that the coordinator is informed about what happened to the resources using different transaction models).
In the JTS case the code you cite indicates that the OTS resource has already said it can commit the work (_prepared == true) but when we called rollback we got an unexpected error so we do not know what it did but we can be sure it will/has either committed or rolled back, hence the HeuristicHazard exception. But if we do not know whether or not it has said it can commit the work (_prepared == false) and we got an unexpected error on the rollback request then the best we can do is report it as a SystemException (CORBA Unknown).
I think Tom and Mike have provided great answers to this question.
OK. Thank you for comprehensive answer. I do now understand the reasons behind.