{"record":{"id":"31d1f1f1fbb0b9a2","repo":"hibernate/hibernate-orm","slug":"could-not-create-connection-31d1f1","errorCode":null,"errorMessage":"Could not create connection","messagePattern":"Could not create connection","errorType":"exception","errorClass":"JDBCConnectionException","httpStatus":null,"severity":"error","filePath":"hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java","lineNumber":222,"sourceCode":"\t\t\t\t\tdialect.getVersion(),\n\t\t\t\t\thasSchema,\n\t\t\t\t\thasCatalog,\n\t\t\t\t\tschema,\n\t\t\t\t\tcatalog,\n\t\t\t\t\tBoolean.toString( autocommit ),\n\t\t\t\t\tisolation == null ? null : toIsolationNiceName( isolation ),\n\t\t\t\t\trequireNonNullElse( getInteger( C3P0_STYLE_MIN_POOL_SIZE.substring( 5 ), poolSettings ),\n\t\t\t\t\t\t\tDEFAULT_MIN_POOL_SIZE ),\n\t\t\t\t\trequireNonNullElse( getInteger( C3P0_STYLE_MAX_POOL_SIZE.substring( 5 ), poolSettings ),\n\t\t\t\t\t\t\tDEFAULT_MAX_POOL_SIZE ),\n\t\t\t\t\tfetchSize\n\t\t\t);\n\t\t\tif ( !connection.getAutoCommit() ) {\n\t\t\t\tconnection.rollback();\n\t\t\t}\n\t\t}\n\t\tcatch (SQLException e) {\n\t\t\tthrow new JDBCConnectionException( \"Could not create connection\", e );\n\t\t}\n\t}\n\n\tprivate DataSource createDataSource(String jdbcUrl, Properties connectionProps, Map<String, Object> poolProperties) {\n\t\ttry {\n\t\t\treturn pooledDataSource( unpooledDataSource( jdbcUrl, connectionProps ), poolProperties );\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tCONNECTION_INFO_LOGGER.unableToInstantiateConnectionPool( e );\n\t\t\tthrow new ConnectionProviderConfigurationException(\n\t\t\t\t\t\"Could not configure c3p0: \" + e.getMessage(),  e );\n\t\t}\n\t}\n\n\tprivate void loadDriverClass(String jdbcDriverClass) {\n\t\tif ( jdbcDriverClass == null ) {\n\t\t\tCONNECTION_INFO_LOGGER.jdbcDriverNotSpecified();\n\t\t}","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java#L204-L240","documentation":"On dialects that cannot render NULLS FIRST/NULLS LAST (supportsNullPrecedence() == false, e.g. MySQL), the full-join emulation adds a synthesized case-expression select item that encodes null precedence, and records its select index per SortSpecification. This IllegalStateException is an internal invariant failure: rendering found null precedence requested but no recorded index for the sort item, meaning the helper column was never registered - a translator bug, not a user query error per se.","triggerScenarios":"Full join + ORDER BY with explicit null precedence (HQL 'nulls first/last', Criteria Nulls.FIRST/NULLS.LAST, or the hibernate.default_null_precedence setting) on a dialect without null-precedence support, hitting a code path where collectSortNullPrecedenceEmulationExpressions did not register indexes for that sort specification.","commonSituations":"Setting default_null_precedence globally and then running full-join queries on MySQL; explicit 'nulls last' on optional sort columns of the full-joined side; regressions after a Hibernate 7.x upgrade on the emulation path.","solutions":["Remove the explicit nulls first/last for that order item (or unset default_null_precedence) so no emulation column is needed.","Ensure the ordered expression is in the select list - helper-column registration depends on the sort expression indexes being present.","Emulate null precedence manually: order by 'case when x is null then 1 else 0 end, x' as a selected expression.","Upgrade to the newest Hibernate 7.x; if it persists, report an HHH issue with the query - IllegalStateException here indicates a framework defect."],"exampleFix":"// before: explicit null precedence on a dialect without native support\n\"select a, i.label from A a full join a.items i order by i.label nulls last\"\n\n// after: manual null-precedence emulation via a selected case expression\n\"select a, i.label, case when i.label is null then 1 else 0 end as nl\n from A a full join a.items i order by nl, i.label\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    return query.getResultList();\n} catch ( IllegalStateException e ) {\n    if ( e.getMessage() != null && e.getMessage().contains(\"null precedence index is missing\") ) {\n        // internal translator invariant: drop explicit nulls first/last and retry without full join\n        return runWithoutNullPrecedence( query );\n    }\n    throw e;\n}","preventionTips":["Avoid explicit 'nulls first/last' on full-join queries when the dialect lacks null-precedence support (MySQL family).","Set default_null_precedence deliberately - a global default hits every emulated order-by.","Report IllegalStateException hits here to Hibernate; it indicates a translator defect, so pin the version once a fix lands."],"tags":["full-join","null-precedence","internal","union","dialect-limitation"],"backgroundTag":"full-join-emulation","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}