Wednesday, February 4, 2009

Using SUPPORTS transaction attribute doesn't work when a transaction has become inactive

In our message receivers, we are sending an event after an exception has occured.

In our receiver method:

h.handle(message);
} catch (Throwable e) {
logger.error("Error in handling message", ExceptionUtils.getRootCause(e));
MessageProcessingErrorEvent mpe = new MessageProcessingErrorEvent(userManagement.getUserBusUnitGuid(),
e);
mpe.send();
throw new XmRuntimeException(e.toString(),e);
}


The sending of the event fails because we look up the user's busUnitGuid and this requires a transaction. The receiver method is being run in a transaction itself.

I thought one solution to this problem would be to put SUPPORTS transaction attribute on the getUserBusUnitGuid() method. The SUPPORTS attribute says that it will go under a transaction if one is present, otherwise it will run without a transaction.

It didn't fix the problem though, it was still saying that the transaction was inactive. Probably JBoss realised there was a transaction attached, so tried to use it, but then discovered it was inactive.

No comments: