{"record":{"id":"004094e9d62b796a","repo":"hibernate/hibernate-orm","slug":"could-not-obtain-transactionmanager-from-jtaplatfo","errorCode":null,"errorMessage":"Could not obtain TransactionManager from JtaPlatform","messagePattern":"Could not obtain TransactionManager from JtaPlatform","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/context/internal/JTASessionContext.java","lineNumber":64,"sourceCode":"public class JTASessionContext extends AbstractCurrentSessionContext {\n\n\tprivate transient final Map<Object, Session> currentSessionMap = new ConcurrentHashMap<>();\n\n\t/**\n\t * Constructs a JTASessionContext\n\t *\n\t * @param factory The factory this context will service\n\t */\n\tpublic JTASessionContext(SessionFactoryImplementor factory) {\n\t\tsuper( factory );\n\t}\n\n\t@Override\n\tpublic Session currentSession() throws HibernateException {\n\t\tfinal var jtaPlatform = factory().getServiceRegistry().requireService( JtaPlatform.class );\n\t\tfinal var transactionManager = jtaPlatform.retrieveTransactionManager();\n\t\tif ( transactionManager == null ) {\n\t\t\tthrow new HibernateException( \"Could not obtain TransactionManager from JtaPlatform\" );\n\t\t}\n\n\t\tfinal var txn = getTransaction( transactionManager );\n\t\tfinal Object txnIdentifier = jtaPlatform.getTransactionIdentifier( txn );\n\n\t\tSession currentSession = currentSessionMap.get( txnIdentifier );\n\t\tif ( currentSession == null ) {\n\t\t\tcurrentSession = buildOrObtainSession();\n\t\t\tregisterSynchronization( txn, txnIdentifier, currentSession );\n\t\t\tcurrentSessionMap.put( txnIdentifier, currentSession );\n\t\t}\n\t\telse {\n\t\t\tvalidateExistingSession( currentSession );\n\t\t}\n\n\t\treturn currentSession;\n\t}\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/context/internal/JTASessionContext.java#L46-L82","documentation":"With hibernate.current_session_context_class=jta, JTASessionContext.currentSession() asks the JtaPlatform service for the JTA TransactionManager to key sessions by transaction. If retrieveTransactionManager() returns null — typically because the default NoJtaPlatform is in effect since no real JTA environment was detected or configured — this HibernateException is thrown before any session is built.","triggerScenarios":"sessionFactory.getCurrentSession() on a factory configured for JTA current-session context while the resolved JtaPlatform is NoJtaPlatform: plain JVM/SE setup with no transaction manager, missing/typo'd hibernate.transaction.jta.platform property, or JNDI lookups failing outside the app server.","commonSituations":"Unit tests run in the IDE without the Arjuna/Narayana JTA provider on the classpath; Spring Boot apps setting the context to 'jta' without enabling JTA; migrating an app from WildFly to SE while keeping the JTA setting; typo in the JtaPlatform FQCN silently falling back to the default.","solutions":["Set a concrete platform: hibernate.transaction.jta.platform=org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform (or the matching class for your TM/server)","Add a real JTA provider to the classpath (org.jboss.narayana:arjuna + JTA artifacts) so platform resolution can succeed","If you do not actually use JTA, switch to hibernate.current_session_context_class=thread (SE) or remove the property in full EE containers where it is derived automatically","Verify the container's JNDI names for the TransactionManager (java:/TransactionManager, java:comp/UserTransaction) match what the chosen platform expects"],"exampleFix":"// before\nMap<String, Object> cfg = new HashMap<>();\ncfg.put(\"hibernate.current_session_context_class\", \"jta\");\n// no JTA provider -> getCurrentSession() throws\n\n// after\ncfg.put(\"hibernate.current_session_context_class\", \"jta\");\ncfg.put(\"hibernate.transaction.jta.platform\",\n        \"org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform\");","handlingStrategy":"validation","validationCode":"org.hibernate.service.jta.platform.spi.JtaPlatform platform =\n        sessionFactory.getServiceRegistry().requireService(org.hibernate.service.jta.platform.spi.JtaPlatform.class);\nif (platform.retrieveTransactionManager() == null) {\n    throw new IllegalStateException(\"No JTA TransactionManager available; set hibernate.transaction.jta.platform before using current sessions\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return sessionFactory.getCurrentSession();\n} catch (org.hibernate.HibernateException e) {\n    if (e.getMessage().contains(\"Could not obtain TransactionManager\")) {\n        throw new IllegalStateException(\"JTA platform misconfigured: no TransactionManager. Check hibernate.transaction.jta.platform and JTA provider on classpath\", e);\n    }\n    throw e;\n}","preventionTips":["Set hibernate.transaction.jta.platform explicitly in SE environments","Add the JTA provider (Narayana/Atomikos) as a first-class test dependency","Smoke-test getCurrentSession() once at startup to fail fast on wiring errors"],"tags":["hibernate","jta","transaction-manager","configuration","current-session"],"backgroundTag":"jta-transaction-manager-missing","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}