{"record":{"id":"f295c1b26084db25","repo":"quarkusio/quarkus","slug":"not-supported-for-transaction-scoped-entity-manage-f295c1","errorCode":null,"errorMessage":"Not supported for transaction scoped entity managers","messagePattern":"Not supported for transaction scoped entity managers","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/session/TransactionScopedStatelessSession.java","lineNumber":286,"sourceCode":"    }\n\n    @Override\n    public void joinTransaction() {\n        try (SessionResult emr = acquireSession()) {\n            emr.statelessSession.joinTransaction();\n        }\n    }\n\n    @Override\n    public boolean isJoinedToTransaction() {\n        try (SessionResult emr = acquireSession()) {\n            return emr.statelessSession.isJoinedToTransaction();\n        }\n    }\n\n    @Override\n    public void close() {\n        throw new IllegalStateException(\"Not supported for transaction scoped entity managers\");\n    }\n\n    @Override\n    public Object insert(Object o) {\n        checkBlocking();\n        try (SessionResult emr = acquireSession()) {\n            return emr.statelessSession.insert(o);\n        }\n    }\n\n    @Override\n    public Object insert(String s, Object o) {\n        checkBlocking();\n        try (SessionResult emr = acquireSession()) {\n            return emr.statelessSession.insert(s, o);\n        }\n    }\n","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/session/TransactionScopedStatelessSession.java#L268-L304","documentation":"A transaction-scoped session is created and destroyed per transaction/invocation and is managed by Quarkus; the user must never close it manually. Calling close() therefore throws IllegalStateException.","triggerScenarios":"Explicitly calling statelessSession.close() (or Session.close() on a transaction-scoped session) in application code, e.g. in a finally block copied from plain-Hibernate code or try-with-resources on the injected session.","commonSituations":"Porting vanilla Hibernate code with try-with-resources around the session; defensive cleanup in finally blocks; wrapping the injected session in try-with-resources accidentally.","solutions":["Remove the close() call — Quarkus closes the transaction-scoped session automatically","Scope the work with @Transactional instead of manual session lifecycle management","Use a manual (application-managed) session via entityManagerFactory().createEntityManager() only if you truly need manual close semantics"],"exampleFix":"// before\ntry (StatelessSession s = injectedStatelessSession) { s.insert(o); } // close() throws\n// after\n@Transactional\npublic void add(Object o) { injectedStatelessSession.insert(o); }","handlingStrategy":"type-guard","validationCode":"// never call close() on injected sessions; guard by ownership check\nif (session instanceof TransactionScopedStatelessSession) {\n    // managed by Quarkus: do NOT close\n}","typeGuard":"boolean isContainerManaged(StatelessSession s) {\n    return s instanceof TransactionScopedStatelessSession;\n}","tryCatchPattern":"try {\n    doWork(statelessSession);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Not supported\")) {\n        Log.warn(\"Attempted to close a container-managed session\");\n    } else { throw e; }\n}","preventionTips":["Never wrap injected sessions in try-with-resources","Remove close()/finally cleanup copied from plain Hibernate code","Let Quarkus manage session lifecycle; scope work with @Transactional"],"tags":["jpa","hibernate-orm","lifecycle"],"backgroundTag":"invalid-session-close","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"}