Tel Map

Blog

Get the Current Transaction in Wildfly

Recently we had a problem with a broken transaction in an application running in Wildfly 20.
javax.persistence.TransactionRequiredException: WFLYJPA0060: Transaction is required to perform this operation (either use a transaction or extended persistence context)

We were not shure which line caused the exception, as the stacktrace was not very specific. So we debugged the application step by step and checked with the following code if the transaction was set to rollback or was still active:
CDI.current().select(TransactionSynchronizationRegistry.class).get().getTransactionStatus()

As long as the status 1 (ACTIVE) was returned the transaction was still valid, but at the subroutine the status switched to 4 (MARKED_ROLLBACK).

We then could check what the exception was and change the Exception so that it does not rollback the transaction by annotating it with @ApplicationException(rollback = false)

I Hope that this will help some of you when you encounter a broken transaction when debugging.
Thank you for reading!

20.07.2021 |

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert