{"record":{"id":"76ee68cc6c576210","repo":"hibernate/hibernate-orm","slug":"unknown-object-type-found-in-jndi-location","errorCode":null,"errorMessage":"Unknown object type [{}] found in JNDI location [{}]","messagePattern":"Unknown object type \\[(.+?)\\] found in JNDI location \\[(.+?)\\]","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java","lineNumber":107,"sourceCode":"\t\t}\n\t\telse if ( namedObject instanceof DataSource datasource ) {\n\t\t\tfinal int loc = jndiName.lastIndexOf( '/' );\n\t\t\tbaseJndiNamespace = jndiName.substring( 0, loc );\n\t\t\tfinal String prefix = jndiName.substring( loc + 1);\n\t\t\ttenantIdentifierForAny = (T) prefix;\n\t\t\tdataSourceMap().put( tenantIdentifierForAny, datasource );\n\t\t}\n\t\telse if ( namedObject instanceof Context ) {\n\t\t\tbaseJndiNamespace = jndiName;\n\t\t\tfinal Object configuredTenantId =\n\t\t\t\t\tconfigurationService.getSettings().get( TENANT_IDENTIFIER_TO_USE_FOR_ANY_KEY );\n\t\t\ttenantIdentifierForAny = (T) configuredTenantId;\n\t\t\tif ( tenantIdentifierForAny == null ) {\n\t\t\t\tthrow new HibernateException( \"JNDI name named a Context, but tenant identifier to use for ANY was not specified\" );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tthrow new HibernateException(\n\t\t\t\t\t\"Unknown object type [\" + namedObject.getClass().getName() +\n\t\t\t\t\t\"] found in JNDI location [\" + this.jndiName + \"]\"\n\t\t\t);\n\t\t}\n\t}\n\n\t@Override\n\tpublic void stop() {\n\t\tdataSourceMap.clear();\n\t}\n\n\t@Override\n\tpublic DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {\n\t\treturn new DatabaseConnectionInfoImpl(\n\t\t\t\tnull,\n\t\t\t\tnull,\n\t\t\t\tnull,\n\t\t\t\tdialect.getClass(),","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DataSourceBasedMultiTenantConnectionProviderImpl.java#L89-L125","documentation":"The object bound at the configured JNDI name was successfully located, but it is neither a javax.sql.DataSource nor a javax.naming.Context. DataSourceBasedMultiTenantConnectionProviderImpl only understands these two shapes (a DataSource to treat as the 'any' tenant plus a namespace prefix, or a Context of per-tenant DataSources), so any other type is rejected with the bound object's class name.","triggerScenarios":"jndiService.locate(jndiName) returns e.g. a String, java.net.URL, ConnectionFactory, Reference, or a lazy proxy that is neither DataSource nor Context - common when the name targets the wrong subnode or a non-JDBC resource.","commonSituations":"Pointing hibernate.connection.datasource at a JCA resource, a JMS connection factory, or an env-entry by mistake; bindings that return javax.naming.Reference before the resource is fully deployed; copy-paste of the wrong JNDI name.","solutions":["Rebind or point the configuration at an object that is a javax.sql.DataSource or a naming Context of DataSources","Inspect what is actually bound: Object o = new InitialContext().lookup(name); System.out.println(o.getClass())","If a Reference/proxy is returned during deployment ordering, ensure the datasource is fully started before Hibernate boots"],"exampleFix":"// before: bound a String reference\nctx.rebind(\"java:/datasources/any\", \"jdbc/mydb\"); // String -> Unknown object type\n\n// after: bind the DataSource itself\nctx.rebind(\"java:/datasources/any\", tenantDataSource);","handlingStrategy":"validation","validationCode":"// assert the bound object has one of the two accepted shapes before bootstrap\nObject o = new InitialContext().lookup(jndiName);\nif ( !(o instanceof DataSource) && !(o instanceof Context) ) {\n    throw new ConfigurationException(\n        \"Expected DataSource or Context at \" + jndiName + \" but found \" + o.getClass().getName());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bind DataSources, never references or Strings, at names Hibernate will consume","Add a startup assertion on the bound object's type in deployment scripts"],"tags":["hibernate","jndi","multitenancy","datasource","type-mismatch"],"backgroundTag":"jndi-wrong-object-type","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}