I'm using XA (2-phase) transaction. I want to log to one log-table through Log class and Entity Manager. My method inside EJB Session bean looks like:
private void logError(Throwable throwable) {
LogEntity logEntity = new LogEntity();
// Set everything
entityManager.persist(logEntity);
}
I want to it in isolated (autonomous) transaction independent of any "outer" transaction. I have already tried to add @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
and @TransactionAttribute(value = TransactionAttributeType.NOT_SUPPORTED)
before method name and does not work.
Before I call EJB3 method I create user transaction like:
try {
UserTransaction transaction = (UserTransaction)context.lookup("javax.transaction.UserTransaction");
transaction.begin();
// Call EJB3 method
transaction.commit();
} catch (Throwable t) {
t.printStackTrace();
try {
transaction.rollback();
} catch (SystemException e) {
e.printStackTrace();
}
}
I want to Log no matter if commit is done or not. How to?
Regards