{"record":{"id":"faafeec393eb020c","repo":"quarkusio/quarkus","slug":"could-not-access-jta-transaction-to-register-synch","errorCode":null,"errorMessage":"Could not access JTA Transaction to register synchronization","messagePattern":"Could not access JTA Transaction to register synchronization","errorType":"exception","errorClass":"JtaPlatformException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/customized/QuarkusJtaPlatform.java","lineNumber":75,"sourceCode":"        UserTransaction userTransaction = this.userTransaction;\n        if (userTransaction == null) {\n            userTransaction = com.arjuna.ats.jta.UserTransaction.userTransaction();\n            this.userTransaction = userTransaction;\n        }\n        return userTransaction;\n    }\n\n    @Override\n    public Object getTransactionIdentifier(final Transaction transaction) {\n        return transaction;\n    }\n\n    @Override\n    public void registerSynchronization(Synchronization synchronization) {\n        try {\n            getTransactionManager().getTransaction().registerSynchronization(synchronization);\n        } catch (Exception e) {\n            throw new JtaPlatformException(\"Could not access JTA Transaction to register synchronization\", e);\n        }\n    }\n\n    @Override\n    public boolean canRegisterSynchronization() {\n        // no need to check STATUS_MARKED_ROLLBACK since synchronizations can't be registered in that state\n        return retrieveTransactionSynchronizationRegistry().getTransactionStatus() == STATUS_ACTIVE;\n    }\n\n    @Override\n    public int getCurrentStatus() throws SystemException {\n        return this.retrieveTransactionManager().getStatus();\n    }\n\n}\n","sourceCodeStart":57,"sourceCodeEnd":91,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/customized/QuarkusJtaPlatform.java#L57-L91","documentation":"QuarkusJtaPlatform.registerSynchronization() obtains the current JTA transaction from the TransactionManager and registers a Hibernate Synchronization on it. If any exception occurs while accessing the transaction (no transaction manager, transaction lookup failure, unexpected status), it wraps the cause in org.hibernate.resource.transaction.spi.JtaPlatformException with this message.","triggerScenarios":"Hibernate ORM calling registerSynchronization (e.g. to flush before queries or register before-completion callbacks) when getTransactionManager().getTransaction() throws — such as when the JTA transaction manager is unavailable or the transaction subsystem is misconfigured.","commonSituations":"Running Hibernate ORM outside a Quarkus-managed context where the transaction manager isn't set; broken Narayana/transaction extension configuration; using a session in a context without proper transaction integration; classloading or ArC initialization problems preventing the TransactionManager lookup.","solutions":["Ensure the quarkus-narayana-jta extension is present and the code runs within Quarkus-managed (CDI/request) context so the TransactionManager is available.","Verify a transaction is actually active when the session is used — annotate with @Transactional or use QuarkusTransaction explicitly.","Inspect the wrapped cause of the JtaPlatformException for the underlying lookup error (e.g. NamingException or NullPointerException).","Avoid sharing EntityManagerFactory/session instances across environments where Quarkus's JTA platform wasn't initialized."],"exampleFix":"// before: session used outside transaction scope\nem.find(Entity.class, id); // registration fails\n\n// after\n@Transactional\nvoid load() { em.find(Entity.class, id); }","handlingStrategy":"try-catch","validationCode":"// Check JTA availability and active transaction before ORM work\njakarta.transaction.TransactionManager tm = getTransactionManager();\nif (tm == null || tm.getTransaction() == null) {\n    throw new IllegalStateException(\"No active JTA transaction; annotate with @Transactional\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return em.find(Entity.class, id);\n} catch (org.hibernate.resource.transaction.spi.JtaPlatformException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Could not access JTA Transaction\")) {\n        throw new IllegalStateException(\n            \"Run ORM work inside a Quarkus-managed @Transactional context\", e);\n    }\n    throw e;\n}","preventionTips":["Always run session/EntityManager work inside @Transactional or QuarkusTransaction scopes","Keep quarkus-narayana-jta on the classpath of applications using Hibernate ORM","Read the wrapped cause of JtaPlatformException to identify lookup failures early","Avoid manual TransactionManager lookups; use Quarkus's transaction APIs"],"tags":["jta","transaction","hibernate-orm","quarkus"],"backgroundTag":"jta-transaction-unavailable","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}