{"record":{"id":"ebcf3a4dd1972a31","repo":"hibernate/hibernate-orm","slug":"unanticipated-error-doing-intermediate-lookup","errorCode":null,"errorMessage":"Unanticipated error doing intermediate lookup","messagePattern":"Unanticipated error doing intermediate lookup","errorType":"exception","errorClass":"JndiException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/jndi/internal/JndiServiceImpl.java","lineNumber":186,"sourceCode":"\t\t\t\tthrow new JndiException( \"Error performing bind [\" + name + \"]\", initialException );\n\t\t\t}\n\n\t\t\t// Otherwise, there is a good chance this may have been caused by missing intermediate contexts.  So we\n\t\t\t// attempt to create those missing intermediate contexts and bind again\n\t\t\tContext intermediateContextBase = context;\n\t\t\twhile ( name.size() > 1 ) {\n\t\t\t\tfinal String intermediateContextName = name.get( 0 );\n\n\t\t\t\tContext intermediateContext = null;\n\t\t\t\ttry {\n\t\t\t\t\tCORE_LOGGER.tracef( \"Intermediate lookup: %s\", intermediateContextName );\n\t\t\t\t\tintermediateContext = (Context) intermediateContextBase.lookup( intermediateContextName );\n\t\t\t\t}\n\t\t\t\tcatch ( NameNotFoundException handledBelow ) {\n\t\t\t\t\t// ok as we will create it below if not found\n\t\t\t\t}\n\t\t\t\tcatch ( NamingException e ) {\n\t\t\t\t\tthrow new JndiException( \"Unanticipated error doing intermediate lookup\", e );\n\t\t\t\t}\n\n\t\t\t\tif ( intermediateContext != null ) {\n\t\t\t\t\tCORE_LOGGER.tracef( \"Found intermediate context: %s\", intermediateContextName );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tCORE_LOGGER.tracef( \"Creating subcontext: %s\", intermediateContextName );\n\t\t\t\t\ttry {\n\t\t\t\t\t\tintermediateContext = intermediateContextBase.createSubcontext( intermediateContextName );\n\t\t\t\t\t}\n\t\t\t\t\tcatch ( NamingException e ) {\n\t\t\t\t\t\tthrow new JndiException( \"Error creating intermediate context [\" + intermediateContextName + \"]\", e );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tintermediateContextBase = intermediateContext;\n\t\t\t\tname = name.getSuffix( 1 );\n\t\t\t}\n\t\t\tCORE_LOGGER.tracef( \"Binding: %s\", name );","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jndi/internal/JndiServiceImpl.java#L168-L204","documentation":"While walking the JNDI tree to create missing parent contexts before binding, the lookup of an intermediate context name threw an unexpected NamingException (not NameNotFoundException, which is expected and handled). The cause carries the provider error.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/jndi/internal/JndiServiceImpl.java:186 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the underlying NamingException cause for the intermediate context failure","Ensure intermediate contexts in the JNDI path exist and are accessible"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}