{"record":{"id":"1521d7df40822aa2","repo":"quarkusio/quarkus","slug":"no-active-transaction-on-the-current-thread","errorCode":null,"errorMessage":"No active transaction on the current thread","messagePattern":"No active transaction on the current thread","errorType":"exception","errorClass":"ContextNotActiveException","httpStatus":null,"severity":"error","filePath":"extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/context/TransactionContext.java","lineNumber":85,"sourceCode":"    }\n\n    @Override\n    public void destroy(Contextual<?> contextual) {\n        if (!isActive()) {\n            return;\n        }\n        TransactionContextState contextState = (TransactionContextState) transactionSynchronizationRegistry.get()\n                .getResource(TRANSACTION_CONTEXT_MARKER);\n        if (contextState == null) {\n            return;\n        }\n        contextState.remove(contextual);\n    }\n\n    @Override\n    public ContextState getState() {\n        if (!isActive()) {\n            throw new ContextNotActiveException(\"No active transaction on the current thread\");\n        }\n\n        ContextState result;\n        TransactionContextState contextState = (TransactionContextState) transactionSynchronizationRegistry.get()\n                .getResource(TRANSACTION_CONTEXT_MARKER);\n        if (contextState == null) {\n            result = new TransactionContextState(getCurrentTransaction());\n        } else {\n            result = contextState;\n        }\n        return result;\n    }\n\n    @Override\n    public Class<? extends Annotation> getScope() {\n        return TransactionScoped.class;\n    }\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/context/TransactionContext.java#L67-L103","documentation":"TransactionContext.getState() implements the CDI AlterableContext contract for the transaction context. If no transaction is active on the current thread (isActive() false), it throws ContextNotActiveException(\"No active transaction on the current thread\"). This surfaces when CDI tries to resolve a @TransactionScoped bean outside an active transaction.","triggerScenarios":"Injecting or accessing a @TransactionScoped bean from code running without @Transactional / without an active JTA transaction; calling getContext(TransactionScoped.class).get(...) manually outside a transaction.","commonSituations":"Forgetting @Transactional on a service method; calling transaction-scoped beans from scheduled tasks, event observers, or background threads without a transaction; programmatic CDI lookups during startup.","solutions":["Add @Transactional (jakarta.transaction.Transactional) to the method or class accessing the bean","Run the code inside @Transactional activator/quarkus-narayana-jta-managed execution (e.g. via TransactionRunner with REQUIRE_NEW semantics)","Move state out of @TransactionScoped into @ApplicationScoped if transaction lifetime is not actually needed"],"exampleFix":"// before\npublic Payment payment() { return transactionScopedBean.get(); }\n// after\n@Transactional\npublic Payment payment() { return transactionScopedBean.get(); }","handlingStrategy":"try-catch","validationCode":"if (!CDI.current().select(TransactionContext.class).get().isActive()) { /* enter a transaction or bail out */ }","typeGuard":"boolean txContextActive() { try { return TransactionManager.transactionManager().getStatus() == Status.STATUS_ACTIVE; } catch (Exception e) { return false; } }","tryCatchPattern":"try { return ctx.getState(); } catch (ContextNotActiveException e) { return null; /* outside transaction */ }","preventionTips":["Access @TransactionScoped beans only from @Transactional methods","Avoid transaction-scoped beans for scheduled/async code paths","Add integration tests that call the bean both with and without a transaction"],"tags":["narayana-jta","cdi","context-not-active","transactions"],"backgroundTag":"no-active-transaction","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"}