{"record":{"id":"40a29aa5b523f11d","repo":"quarkusio/quarkus","slug":"this-build-of-hibernate-orm-doesn-t-support-threa","errorCode":null,"errorMessage":"This build of Hibernate ORM doesn't support 'thread' value for configuration property hibernate.current_session_context_class","messagePattern":"This build of Hibernate ORM doesn't support 'thread' value for configuration property hibernate\\.current_session_context_class","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/graal/context/Substitute_ThreadLocalSessionContext.java","lineNumber":16,"sourceCode":"package io.quarkus.hibernate.orm.runtime.graal.context;\n\nimport org.hibernate.HibernateException;\nimport org.hibernate.Session;\nimport org.hibernate.cfg.AvailableSettings;\nimport org.hibernate.engine.spi.SessionFactoryImplementor;\n\nimport com.oracle.svm.core.annotate.Substitute;\nimport com.oracle.svm.core.annotate.TargetClass;\n\n@TargetClass(className = \"org.hibernate.context.internal.ThreadLocalSessionContext\")\npublic final class Substitute_ThreadLocalSessionContext {\n\n    @Substitute\n    public Substitute_ThreadLocalSessionContext(SessionFactoryImplementor factory) {\n        throw new UnsupportedOperationException(\n                \"This build of Hibernate ORM doesn't support 'thread' value for configuration property\"\n                        + AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS);\n    }\n\n    @Substitute\n    public Session currentSession() throws HibernateException {\n        return null;\n    }\n\n}\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/graal/context/Substitute_ThreadLocalSessionContext.java#L1-L27","documentation":"In native (GraalVM) images, Quarkus substitutes Hibernate ORM's ThreadLocalSessionContext with a stub whose constructor always throws UnsupportedOperationException. The 'thread' JTA-less session-context strategy relies on reflection/thread-local machinery that Quarkus does not support, so it is deliberately disabled at build time. If you got this, your persistence unit is configured with hibernate.current_session_context_class=thread and bootstrapped in a native executable.","triggerScenarios":"Setting hibernate.current_session_context_class=thread (via quarkus.hibernate-orm.* config or persistence.xml AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS) so Hibernate instantiates ThreadLocalSessionContext, whose @Substitute constructor throws during SessionFactory build in a native build.","commonSituations":"Porting a classic Java EE / Spring-style application to Quarkus native that relied on 'thread' session contexts and getCurrentSession(); copying persistence.xml settings from a non-Quarkus project; misunderstanding that Quarkus manages sessions via its own integration (e.g. transaction-scoped sessions through ArC/transaction APIs).","solutions":["Remove the hibernate.current_session_context_class=thread setting entirely; Quarkus manages session/context binding itself.","Instead of session.unwrap/getCurrentSession with 'thread', inject an EntityManager (or Session) via CDI, e.g. @Inject EntityManager em, ideally inside a @Transactional method.","If you must keep legacy code, run in JVM mode (not native) where the substitution does not apply — but prefer refactoring."],"exampleFix":"// before (persistence.xml or properties)\nhibernate.current_session_context_class=thread\nSession s = sessionFactory.getCurrentSession();\n\n// after (Quarkus)\n@Inject EntityManager em;\n@Transactional\npublic void doWork() { em.persist(new Entity()); }","handlingStrategy":"validation","validationCode":"// Fail fast if a native build would break\nif (config.containsProperty(\"quarkus.hibernate-orm.relationships\")) { /* check pu config */ }\n// simplest: assert the setting is absent\nassert !puProperties.containsKey(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS)\n    : \"Remove hibernate.current_session_context_class=thread; Quarkus manages session context\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set hibernate.current_session_context_class in Quarkus apps","Inject EntityManager/Session via CDI instead of getCurrentSession()","Test native builds early (mvn verify -Dnative) to catch Graal substitutions"],"tags":["hibernate-orm","native-image","graalvm","session-context","quarkus"],"backgroundTag":"native-image-unsupported-feature","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"}